2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-03-01 18:35:54 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_MEDIA_FILE_MEDIA_FILE_UTILITY_H_
|
|
|
|
|
#define MODULES_MEDIA_FILE_MEDIA_FILE_UTILITY_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2017-09-15 13:58:09 +02:00
|
|
|
#include "common_types.h" // NOLINT(build/include)
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/media_file/media_file_defines.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
class InStream;
|
|
|
|
|
class OutStream;
|
|
|
|
|
|
|
|
|
|
class ModuleFileUtility
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
2017-08-22 13:44:09 +02:00
|
|
|
ModuleFileUtility();
|
2011-07-07 08:21:25 +00:00
|
|
|
~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.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t InitWavReading(InStream& stream,
|
|
|
|
|
const uint32_t startPointMs = 0,
|
|
|
|
|
const uint32_t stopPointMs = 0);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// 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).
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t ReadWavDataAsMono(InStream& stream, int8_t* audioBuffer,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
const size_t dataLengthInBytes);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// 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.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t ReadWavDataAsStereo(InStream& wav,
|
|
|
|
|
int8_t* audioBufferLeft,
|
|
|
|
|
int8_t* audioBufferRight,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
const size_t bufferLength);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// 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.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t InitWavWriting(OutStream& stream, const CodecInst& codecInst);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// 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.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t WriteWavData(OutStream& stream,
|
|
|
|
|
const int8_t* audioBuffer,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
const size_t bufferLength);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// 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.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t UpdateWavHeader(OutStream& stream);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// 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)
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t InitPCMReading(InStream& stream,
|
|
|
|
|
const uint32_t startPointMs = 0,
|
|
|
|
|
const uint32_t stopPointMs = 0,
|
|
|
|
|
const uint32_t freqInHz = 16000);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// 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.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t ReadPCMData(InStream& stream, int8_t* audioBuffer,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
const size_t dataLengthInBytes);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Prepare for recording audio to stream.
|
|
|
|
|
// freqInHz is the PCM sampling frequency.
|
|
|
|
|
// NOTE, allowed frequencies are 8000, 16000 and 32000 (Hz)
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t InitPCMWriting(OutStream& stream, const uint32_t freqInHz = 16000);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// 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.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t WritePCMData(OutStream& stream,
|
|
|
|
|
const int8_t* audioBuffer,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t bufferLength);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// 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.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t InitCompressedReading(InStream& stream,
|
|
|
|
|
const uint32_t startPointMs = 0,
|
|
|
|
|
const uint32_t stopPointMs = 0);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// 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.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t ReadCompressedData(InStream& stream,
|
|
|
|
|
int8_t* audioBuffer,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
const size_t dataLengthInBytes);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Prepare for recording audio to stream.
|
|
|
|
|
// codecInst specifies the encoding of the audio data.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t InitCompressedWriting(OutStream& stream,
|
|
|
|
|
const CodecInst& codecInst);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// 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.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t WriteCompressedData(OutStream& stream,
|
|
|
|
|
const int8_t* audioBuffer,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
const size_t bufferLength);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Prepare for playing audio from stream.
|
|
|
|
|
// codecInst specifies the encoding of the audio data.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t InitPreEncodedReading(InStream& stream,
|
|
|
|
|
const CodecInst& codecInst);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// 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.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t ReadPreEncodedData(InStream& stream,
|
|
|
|
|
int8_t* audioBuffer,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
const size_t dataLengthInBytes);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Prepare for recording audio to stream.
|
|
|
|
|
// codecInst specifies the encoding of the audio data.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t InitPreEncodedWriting(OutStream& stream,
|
|
|
|
|
const CodecInst& codecInst);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// 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.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t WritePreEncodedData(OutStream& stream,
|
|
|
|
|
const int8_t* inData,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
const size_t dataLengthInBytes);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Set durationMs to the size of the file (in ms) specified by fileName.
|
|
|
|
|
// freqInHz specifies the sampling frequency of the file.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t FileDurationMs(const char* fileName,
|
|
|
|
|
const FileFormats fileFormat,
|
|
|
|
|
const uint32_t freqInHz = 16000);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Return the number of ms that have been played so far.
|
2013-04-09 13:31:37 +00:00
|
|
|
uint32_t PlayoutPositionMs();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Update codecInst according to the current audio codec being used for
|
|
|
|
|
// reading or writing.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t codec_info(CodecInst& codecInst);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
private:
|
2012-02-14 18:17:16 +00:00
|
|
|
// Biggest WAV frame supported is 10 ms at 48kHz of 2 channel, 16 bit audio.
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
static const size_t WAV_MAX_BUFFER_SIZE = 480 * 2 * 2;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t InitWavCodec(uint32_t samplesPerSec,
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t channels,
|
2013-04-09 13:31:37 +00:00
|
|
|
uint32_t bitsPerSample,
|
|
|
|
|
uint32_t formatTag);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Parse the WAV header in stream.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t ReadWavHeader(InStream& stream);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// 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.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t WriteWavHeader(OutStream& stream,
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
uint32_t freqInHz,
|
|
|
|
|
size_t bytesPerSample,
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t channels,
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
uint32_t format,
|
|
|
|
|
size_t lengthInBytes);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Put dataLengthInBytes of audio data from stream into the audioBuffer.
|
|
|
|
|
// The return value is the number of bytes written to audioBuffer.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t ReadWavData(InStream& stream, uint8_t* audioBuffer,
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
size_t dataLengthInBytes);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Update the current audio codec being used for reading or writing
|
|
|
|
|
// according to codecInst.
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t set_codec_info(const CodecInst& codecInst);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
struct WAVE_FMTINFO_header
|
|
|
|
|
{
|
2013-04-09 13:31:37 +00:00
|
|
|
int16_t formatTag;
|
|
|
|
|
int16_t nChannels;
|
|
|
|
|
int32_t nSamplesPerSec;
|
|
|
|
|
int32_t nAvgBytesPerSec;
|
|
|
|
|
int16_t nBlockAlign;
|
|
|
|
|
int16_t nBitsPerSample;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
|
|
|
|
// Identifiers for preencoded files.
|
|
|
|
|
enum MediaFileUtility_CodecType
|
|
|
|
|
{
|
|
|
|
|
kCodecNoCodec = 0,
|
|
|
|
|
kCodecIsac,
|
|
|
|
|
kCodecIsacSwb,
|
|
|
|
|
kCodecIsacLc,
|
|
|
|
|
kCodecL16_8Khz,
|
|
|
|
|
kCodecL16_16kHz,
|
|
|
|
|
kCodecL16_32Khz,
|
2017-09-01 14:36:33 +02:00
|
|
|
kCodecL16_48Khz,
|
2011-07-07 08:21:25 +00:00
|
|
|
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,
|
2017-03-20 05:56:22 -07:00
|
|
|
kCodecG726_16
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// TODO (hellner): why store multiple formats. Just store either codec_info_
|
|
|
|
|
// or _wavFormatObj and supply conversion functions.
|
|
|
|
|
WAVE_FMTINFO_header _wavFormatObj;
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
size_t _dataSize; // Chunk size if reading a WAV file
|
2011-07-07 08:21:25 +00:00
|
|
|
// Number of bytes to read. I.e. frame size in bytes. May be multiple
|
|
|
|
|
// chunks if reading WAV.
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
size_t _readSizeBytes;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-09 13:31:37 +00:00
|
|
|
uint32_t _stopPointInMs;
|
|
|
|
|
uint32_t _startPointInMs;
|
|
|
|
|
uint32_t _playoutPositionMs;
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t _bytesWritten;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
CodecInst codec_info_;
|
|
|
|
|
MediaFileUtility_CodecType _codecId;
|
|
|
|
|
|
|
|
|
|
// The amount of bytes, on average, used for one audio sample.
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
size_t _bytesPerSample;
|
|
|
|
|
size_t _readPos;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Only reading or writing can be enabled, not both.
|
|
|
|
|
bool _reading;
|
|
|
|
|
bool _writing;
|
|
|
|
|
|
|
|
|
|
// Scratch buffer used for turning stereo audio to mono.
|
2013-04-09 13:31:37 +00:00
|
|
|
uint8_t _tempData[WAV_MAX_BUFFER_SIZE];
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_MEDIA_FILE_MEDIA_FILE_UTILITY_H_
|