diff options
author | Chih-hung Hsieh <chh@google.com> | 2016-01-20 17:50:13 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-01-20 17:50:13 +0000 |
commit | b3cb8ab4ede8bb77f0bdef2715efc2c1e6267072 (patch) | |
tree | 28c4cf735dd5bd9cc8f1ccd06fff8a173b20d1cb /webrtc/modules/media_file/media_file_utility.h | |
parent | a4acd9d6bc9b3b033d7d274316e75ee067df8d20 (diff) | |
parent | 9a337512d97e37afc142dee4fd50a41b741a87d2 (diff) | |
download | webrtc-b3cb8ab4ede8bb77f0bdef2715efc2c1e6267072.tar.gz |
Merge "Merge upstream SHA 04cb763"android-cts_7.1_r1android-cts-7.1_r9android-cts-7.1_r8android-cts-7.1_r7android-cts-7.1_r6android-cts-7.1_r5android-cts-7.1_r4android-cts-7.1_r3android-cts-7.1_r29android-cts-7.1_r28android-cts-7.1_r27android-cts-7.1_r26android-cts-7.1_r25android-cts-7.1_r24android-cts-7.1_r23android-cts-7.1_r22android-cts-7.1_r21android-cts-7.1_r20android-cts-7.1_r2android-cts-7.1_r19android-cts-7.1_r18android-cts-7.1_r17android-cts-7.1_r16android-cts-7.1_r15android-cts-7.1_r14android-cts-7.1_r13android-cts-7.1_r12android-cts-7.1_r11android-cts-7.1_r10android-cts-7.1_r1android-cts-7.0_r9android-cts-7.0_r8android-cts-7.0_r7android-cts-7.0_r6android-cts-7.0_r5android-cts-7.0_r4android-cts-7.0_r33android-cts-7.0_r32android-cts-7.0_r31android-cts-7.0_r30android-cts-7.0_r3android-cts-7.0_r29android-cts-7.0_r28android-cts-7.0_r27android-cts-7.0_r26android-cts-7.0_r25android-cts-7.0_r24android-cts-7.0_r23android-cts-7.0_r22android-cts-7.0_r21android-cts-7.0_r20android-cts-7.0_r2android-cts-7.0_r19android-cts-7.0_r18android-cts-7.0_r17android-cts-7.0_r16android-cts-7.0_r15android-cts-7.0_r14android-cts-7.0_r13android-cts-7.0_r12android-cts-7.0_r11android-cts-7.0_r10android-cts-7.0_r1android-7.1.2_r9android-7.1.2_r8android-7.1.2_r6android-7.1.2_r5android-7.1.2_r4android-7.1.2_r39android-7.1.2_r38android-7.1.2_r37android-7.1.2_r36android-7.1.2_r33android-7.1.2_r32android-7.1.2_r30android-7.1.2_r3android-7.1.2_r29android-7.1.2_r28android-7.1.2_r27android-7.1.2_r25android-7.1.2_r24android-7.1.2_r23android-7.1.2_r2android-7.1.2_r19android-7.1.2_r18android-7.1.2_r17android-7.1.2_r16android-7.1.2_r15android-7.1.2_r14android-7.1.2_r13android-7.1.2_r12android-7.1.2_r11android-7.1.2_r10android-7.1.2_r1android-7.1.1_r9android-7.1.1_r8android-7.1.1_r7android-7.1.1_r61android-7.1.1_r60android-7.1.1_r6android-7.1.1_r59android-7.1.1_r58android-7.1.1_r57android-7.1.1_r56android-7.1.1_r55android-7.1.1_r54android-7.1.1_r53android-7.1.1_r52android-7.1.1_r51android-7.1.1_r50android-7.1.1_r49android-7.1.1_r48android-7.1.1_r47android-7.1.1_r46android-7.1.1_r45android-7.1.1_r44android-7.1.1_r43android-7.1.1_r42android-7.1.1_r41android-7.1.1_r40android-7.1.1_r4android-7.1.1_r39android-7.1.1_r38android-7.1.1_r35android-7.1.1_r33android-7.1.1_r32android-7.1.1_r31android-7.1.1_r3android-7.1.1_r28android-7.1.1_r27android-7.1.1_r26android-7.1.1_r25android-7.1.1_r24android-7.1.1_r23android-7.1.1_r22android-7.1.1_r21android-7.1.1_r20android-7.1.1_r2android-7.1.1_r17android-7.1.1_r16android-7.1.1_r15android-7.1.1_r14android-7.1.1_r13android-7.1.1_r12android-7.1.1_r11android-7.1.1_r10android-7.1.1_r1android-7.1.0_r7android-7.1.0_r6android-7.1.0_r5android-7.1.0_r4android-7.1.0_r3android-7.1.0_r2android-7.1.0_r1android-7.0.0_r9android-7.0.0_r8android-7.0.0_r7android-7.0.0_r6android-7.0.0_r5android-7.0.0_r4android-7.0.0_r36android-7.0.0_r35android-7.0.0_r34android-7.0.0_r33android-7.0.0_r32android-7.0.0_r31android-7.0.0_r30android-7.0.0_r3android-7.0.0_r29android-7.0.0_r28android-7.0.0_r27android-7.0.0_r24android-7.0.0_r21android-7.0.0_r19android-7.0.0_r17android-7.0.0_r15android-7.0.0_r14android-7.0.0_r13android-7.0.0_r12android-7.0.0_r11android-7.0.0_r10android-7.0.0_r1nougat-releasenougat-mr2.3-releasenougat-mr2.2-releasenougat-mr2.1-releasenougat-mr2-security-releasenougat-mr2-releasenougat-mr2-pixel-releasenougat-mr2-devnougat-mr1.8-releasenougat-mr1.7-releasenougat-mr1.6-releasenougat-mr1.5-releasenougat-mr1.4-releasenougat-mr1.3-releasenougat-mr1.2-releasenougat-mr1.1-releasenougat-mr1-volantis-releasenougat-mr1-security-releasenougat-mr1-releasenougat-mr1-flounder-releasenougat-mr1-devnougat-mr1-cts-releasenougat-mr0.5-releasenougat-dr1-releasenougat-devnougat-cts-releasenougat-bugfix-release
am: 9a337512d9
* commit '9a337512d97e37afc142dee4fd50a41b741a87d2': (797 commits)
Add tests for verifying transport feedback for audio and video.
Eliminate defines in talk/
Revert of Update with new default boringssl no-aes cipher suites. Re-enable tests. (patchset #3 id:40001 of https://codereview.webrtc.org/1550773002/ )
Remove assert which was incorrectly added to TcpPort::OnSentPacket.
Reland Connect TurnPort and TCPPort to AsyncPacketSocket::SignalSentPacket.
Update with new default boringssl no-aes cipher suites. Re-enable tests.
Revert of Connect TurnPort and TCPPort to AsyncPacketSocket::SignalSentPacket. (patchset #3 id:40001 of https://codereview.webrtc.org/1577873003/ )
Re-land: "Use an explicit identifier in Config"
Connect TurnPort and TCPPort to AsyncPacketSocket::SignalSentPacket.
Revert of Delete remnants of non-square pixel support from cricket::VideoFrame. (patchset #1 id:1 of https://codereview.webrtc.org/1586613002/ )
Remove libfuzzer trybot from default trybot set.
Add ramp-up tests for transport sequence number with and w/o audio.
Delete remnants of non-square pixel support from cricket::VideoFrame.
Fix IPAddress::ToSensitiveString() to avoid dependency on inet_ntop().
Revert of Storing raw audio sink for default audio track. (patchset #7 id:120001 of https://codereview.chromium.org/1551813002/ )
Re-enable tests that failed under Linux_Msan.
Revert of Use an explicit identifier in Config (patchset #4 id:60001 of https://codereview.webrtc.org/1538643004/ )
Roll chromium_revision 346fea9..099be58 (369082:369139)
Disable WebRtcVideoChannel2BaseTest.SendManyResizeOnce for TSan
Add build_protobuf variable.
...
Diffstat (limited to 'webrtc/modules/media_file/media_file_utility.h')
-rw-r--r-- | webrtc/modules/media_file/media_file_utility.h | 284 |
1 files changed, 284 insertions, 0 deletions
diff --git a/webrtc/modules/media_file/media_file_utility.h b/webrtc/modules/media_file/media_file_utility.h new file mode 100644 index 0000000000..bc2fa5a2f0 --- /dev/null +++ b/webrtc/modules/media_file/media_file_utility.h @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +// Note: the class cannot be used for reading and writing at the same time. +#ifndef WEBRTC_MODULES_MEDIA_FILE_MEDIA_FILE_UTILITY_H_ +#define WEBRTC_MODULES_MEDIA_FILE_MEDIA_FILE_UTILITY_H_ + +#include <stdio.h> + +#include "webrtc/common_types.h" +#include "webrtc/modules/media_file/media_file_defines.h" + +namespace webrtc { +class InStream; +class OutStream; + +class ModuleFileUtility +{ +public: + + ModuleFileUtility(const int32_t id); + ~ModuleFileUtility(); + + // Prepare for playing audio from stream. + // startPointMs and stopPointMs, unless zero, specify what part of the file + // should be read. From startPointMs ms to stopPointMs ms. + int32_t InitWavReading(InStream& stream, + const uint32_t startPointMs = 0, + const uint32_t stopPointMs = 0); + + // Put 10-60ms of audio data from stream into the audioBuffer depending on + // codec frame size. dataLengthInBytes indicates the size of audioBuffer. + // The return value is the number of bytes written to audioBuffer. + // Note: This API only play mono audio but can be used on file containing + // audio with more channels (in which case the audio will be converted to + // mono). + int32_t ReadWavDataAsMono(InStream& stream, int8_t* audioBuffer, + const size_t dataLengthInBytes); + + // Put 10-60ms, depending on codec frame size, of audio data from file into + // audioBufferLeft and audioBufferRight. The buffers contain the left and + // right channel of played out stereo audio. + // dataLengthInBytes indicates the size of both audioBufferLeft and + // audioBufferRight. + // The return value is the number of bytes read for each buffer. + // Note: This API can only be successfully called for WAV files with stereo + // audio. + int32_t ReadWavDataAsStereo(InStream& wav, + int8_t* audioBufferLeft, + int8_t* audioBufferRight, + const size_t bufferLength); + + // Prepare for recording audio to stream. + // codecInst specifies the encoding of the audio data. + // Note: codecInst.channels should be set to 2 for stereo (and 1 for + // mono). Stereo is only supported for WAV files. + int32_t InitWavWriting(OutStream& stream, const CodecInst& codecInst); + + // Write one audio frame, i.e. the bufferLength first bytes of audioBuffer, + // to file. The audio frame size is determined by the codecInst.pacsize + // parameter of the last sucessfull StartRecordingAudioFile(..) call. + // The return value is the number of bytes written to audioBuffer. + int32_t WriteWavData(OutStream& stream, + const int8_t* audioBuffer, + const size_t bufferLength); + + // Finalizes the WAV header so that it is correct if nothing more will be + // written to stream. + // Note: this API must be called before closing stream to ensure that the + // WAVE header is updated with the file size. Don't call this API + // if more samples are to be written to stream. + int32_t UpdateWavHeader(OutStream& stream); + + // Prepare for playing audio from stream. + // startPointMs and stopPointMs, unless zero, specify what part of the file + // should be read. From startPointMs ms to stopPointMs ms. + // freqInHz is the PCM sampling frequency. + // NOTE, allowed frequencies are 8000, 16000 and 32000 (Hz) + int32_t InitPCMReading(InStream& stream, + const uint32_t startPointMs = 0, + const uint32_t stopPointMs = 0, + const uint32_t freqInHz = 16000); + + // Put 10-60ms of audio data from stream into the audioBuffer depending on + // codec frame size. dataLengthInBytes indicates the size of audioBuffer. + // The return value is the number of bytes written to audioBuffer. + int32_t ReadPCMData(InStream& stream, int8_t* audioBuffer, + const size_t dataLengthInBytes); + + // Prepare for recording audio to stream. + // freqInHz is the PCM sampling frequency. + // NOTE, allowed frequencies are 8000, 16000 and 32000 (Hz) + int32_t InitPCMWriting(OutStream& stream, const uint32_t freqInHz = 16000); + + // Write one 10ms audio frame, i.e. the bufferLength first bytes of + // audioBuffer, to file. The audio frame size is determined by the freqInHz + // parameter of the last sucessfull InitPCMWriting(..) call. + // The return value is the number of bytes written to audioBuffer. + int32_t WritePCMData(OutStream& stream, + const int8_t* audioBuffer, + size_t bufferLength); + + // Prepare for playing audio from stream. + // startPointMs and stopPointMs, unless zero, specify what part of the file + // should be read. From startPointMs ms to stopPointMs ms. + int32_t InitCompressedReading(InStream& stream, + const uint32_t startPointMs = 0, + const uint32_t stopPointMs = 0); + + // Put 10-60ms of audio data from stream into the audioBuffer depending on + // codec frame size. dataLengthInBytes indicates the size of audioBuffer. + // The return value is the number of bytes written to audioBuffer. + int32_t ReadCompressedData(InStream& stream, + int8_t* audioBuffer, + const size_t dataLengthInBytes); + + // Prepare for recording audio to stream. + // codecInst specifies the encoding of the audio data. + int32_t InitCompressedWriting(OutStream& stream, + const CodecInst& codecInst); + + // Write one audio frame, i.e. the bufferLength first bytes of audioBuffer, + // to file. The audio frame size is determined by the codecInst.pacsize + // parameter of the last sucessfull InitCompressedWriting(..) call. + // The return value is the number of bytes written to stream. + // Note: bufferLength must be exactly one frame. + int32_t WriteCompressedData(OutStream& stream, + const int8_t* audioBuffer, + const size_t bufferLength); + + // Prepare for playing audio from stream. + // codecInst specifies the encoding of the audio data. + int32_t InitPreEncodedReading(InStream& stream, + const CodecInst& codecInst); + + // Put 10-60ms of audio data from stream into the audioBuffer depending on + // codec frame size. dataLengthInBytes indicates the size of audioBuffer. + // The return value is the number of bytes written to audioBuffer. + int32_t ReadPreEncodedData(InStream& stream, + int8_t* audioBuffer, + const size_t dataLengthInBytes); + + // Prepare for recording audio to stream. + // codecInst specifies the encoding of the audio data. + int32_t InitPreEncodedWriting(OutStream& stream, + const CodecInst& codecInst); + + // Write one audio frame, i.e. the bufferLength first bytes of audioBuffer, + // to stream. The audio frame size is determined by the codecInst.pacsize + // parameter of the last sucessfull InitPreEncodedWriting(..) call. + // The return value is the number of bytes written to stream. + // Note: bufferLength must be exactly one frame. + int32_t WritePreEncodedData(OutStream& stream, + const int8_t* inData, + const size_t dataLengthInBytes); + + // Set durationMs to the size of the file (in ms) specified by fileName. + // freqInHz specifies the sampling frequency of the file. + int32_t FileDurationMs(const char* fileName, + const FileFormats fileFormat, + const uint32_t freqInHz = 16000); + + // Return the number of ms that have been played so far. + uint32_t PlayoutPositionMs(); + + // Update codecInst according to the current audio codec being used for + // reading or writing. + int32_t codec_info(CodecInst& codecInst); + +private: + // Biggest WAV frame supported is 10 ms at 48kHz of 2 channel, 16 bit audio. + static const size_t WAV_MAX_BUFFER_SIZE = 480 * 2 * 2; + + + int32_t InitWavCodec(uint32_t samplesPerSec, + size_t channels, + uint32_t bitsPerSample, + uint32_t formatTag); + + // Parse the WAV header in stream. + int32_t ReadWavHeader(InStream& stream); + + // Update the WAV header. freqInHz, bytesPerSample, channels, format, + // lengthInBytes specify characterists of the audio data. + // freqInHz is the sampling frequency. bytesPerSample is the sample size in + // bytes. channels is the number of channels, e.g. 1 is mono and 2 is + // stereo. format is the encode format (e.g. PCMU, PCMA, PCM etc). + // lengthInBytes is the number of bytes the audio samples are using up. + int32_t WriteWavHeader(OutStream& stream, + uint32_t freqInHz, + size_t bytesPerSample, + size_t channels, + uint32_t format, + size_t lengthInBytes); + + // Put dataLengthInBytes of audio data from stream into the audioBuffer. + // The return value is the number of bytes written to audioBuffer. + int32_t ReadWavData(InStream& stream, uint8_t* audioBuffer, + size_t dataLengthInBytes); + + // Update the current audio codec being used for reading or writing + // according to codecInst. + int32_t set_codec_info(const CodecInst& codecInst); + + struct WAVE_FMTINFO_header + { + int16_t formatTag; + int16_t nChannels; + int32_t nSamplesPerSec; + int32_t nAvgBytesPerSec; + int16_t nBlockAlign; + int16_t nBitsPerSample; + }; + // Identifiers for preencoded files. + enum MediaFileUtility_CodecType + { + kCodecNoCodec = 0, + kCodecIsac, + kCodecIsacSwb, + kCodecIsacLc, + kCodecL16_8Khz, + kCodecL16_16kHz, + kCodecL16_32Khz, + kCodecPcmu, + kCodecPcma, + kCodecIlbc20Ms, + kCodecIlbc30Ms, + kCodecG722, + kCodecG722_1_32Kbps, + kCodecG722_1_24Kbps, + kCodecG722_1_16Kbps, + kCodecG722_1c_48, + kCodecG722_1c_32, + kCodecG722_1c_24, + kCodecAmr, + kCodecAmrWb, + kCodecG729, + kCodecG729_1, + kCodecG726_40, + kCodecG726_32, + kCodecG726_24, + kCodecG726_16, + kCodecSpeex8Khz, + kCodecSpeex16Khz + }; + + // TODO (hellner): why store multiple formats. Just store either codec_info_ + // or _wavFormatObj and supply conversion functions. + WAVE_FMTINFO_header _wavFormatObj; + size_t _dataSize; // Chunk size if reading a WAV file + // Number of bytes to read. I.e. frame size in bytes. May be multiple + // chunks if reading WAV. + size_t _readSizeBytes; + + int32_t _id; + + uint32_t _stopPointInMs; + uint32_t _startPointInMs; + uint32_t _playoutPositionMs; + size_t _bytesWritten; + + CodecInst codec_info_; + MediaFileUtility_CodecType _codecId; + + // The amount of bytes, on average, used for one audio sample. + size_t _bytesPerSample; + size_t _readPos; + + // Only reading or writing can be enabled, not both. + bool _reading; + bool _writing; + + // Scratch buffer used for turning stereo audio to mono. + uint8_t _tempData[WAV_MAX_BUFFER_SIZE]; +}; +} // namespace webrtc +#endif // WEBRTC_MODULES_MEDIA_FILE_MEDIA_FILE_UTILITY_H_ |