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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_MODULES_MEDIA_FILE_SOURCE_MEDIA_FILE_IMPL_H_
|
|
|
|
|
#define WEBRTC_MODULES_MEDIA_FILE_SOURCE_MEDIA_FILE_IMPL_H_
|
|
|
|
|
|
2013-07-16 13:05:40 +00:00
|
|
|
#include "webrtc/common_types.h"
|
|
|
|
|
#include "webrtc/modules/interface/module_common_types.h"
|
|
|
|
|
#include "webrtc/modules/media_file/interface/media_file.h"
|
|
|
|
|
#include "webrtc/modules/media_file/interface/media_file_defines.h"
|
|
|
|
|
#include "webrtc/modules/media_file/source/media_file_utility.h"
|
|
|
|
|
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
class MediaFileImpl : public MediaFile
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public:
|
2013-04-09 13:31:37 +00:00
|
|
|
MediaFileImpl(const int32_t id);
|
2011-07-07 08:21:25 +00:00
|
|
|
~MediaFileImpl();
|
|
|
|
|
|
2014-09-11 06:20:28 +00:00
|
|
|
virtual int32_t Process() OVERRIDE;
|
2014-12-15 22:09:40 +00:00
|
|
|
virtual int64_t TimeUntilNextProcess() OVERRIDE;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// MediaFile functions
|
2014-09-11 06:20:28 +00:00
|
|
|
virtual int32_t PlayoutAudioData(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& dataLengthInBytes) OVERRIDE;
|
2015-03-02 13:07:02 +00:00
|
|
|
|
2014-09-11 06:20:28 +00:00
|
|
|
virtual int32_t PlayoutStereoData(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
|
|
|
size_t& dataLengthInBytes) OVERRIDE;
|
2015-03-02 13:07:02 +00:00
|
|
|
|
2013-04-09 13:31:37 +00:00
|
|
|
virtual int32_t StartPlayingAudioFile(
|
2012-03-01 18:35:54 +00:00
|
|
|
const char* fileName,
|
2013-04-09 13:31:37 +00:00
|
|
|
const uint32_t notificationTimeMs = 0,
|
2011-07-07 08:21:25 +00:00
|
|
|
const bool loop = false,
|
|
|
|
|
const FileFormats format = kFileFormatPcm16kHzFile,
|
|
|
|
|
const CodecInst* codecInst = NULL,
|
2013-04-09 13:31:37 +00:00
|
|
|
const uint32_t startPointMs = 0,
|
2014-09-11 06:20:28 +00:00
|
|
|
const uint32_t stopPointMs = 0) OVERRIDE;
|
2015-03-02 13:07:02 +00:00
|
|
|
|
2014-09-11 06:20:28 +00:00
|
|
|
virtual int32_t StartPlayingAudioStream(InStream& stream,
|
2013-04-09 13:31:37 +00:00
|
|
|
const uint32_t notificationTimeMs = 0,
|
|
|
|
|
const FileFormats format = kFileFormatPcm16kHzFile,
|
|
|
|
|
const CodecInst* codecInst = NULL,
|
|
|
|
|
const uint32_t startPointMs = 0,
|
2014-09-11 06:20:28 +00:00
|
|
|
const uint32_t stopPointMs = 0) OVERRIDE;
|
2015-03-02 13:07:02 +00:00
|
|
|
|
2014-09-11 06:20:28 +00:00
|
|
|
virtual int32_t StopPlaying() OVERRIDE;
|
2015-03-02 13:07:02 +00:00
|
|
|
|
2014-09-11 06:20:28 +00:00
|
|
|
virtual bool IsPlaying() OVERRIDE;
|
2015-03-02 13:07:02 +00:00
|
|
|
|
2014-09-11 06:20:28 +00:00
|
|
|
virtual int32_t PlayoutPositionMs(uint32_t& positionMs) const OVERRIDE;
|
2015-03-02 13:07:02 +00:00
|
|
|
|
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
|
|
|
virtual int32_t IncomingAudioData(const int8_t* audioBuffer,
|
|
|
|
|
const size_t bufferLength) OVERRIDE;
|
2015-03-02 13:07:02 +00:00
|
|
|
|
2014-09-11 06:20:28 +00:00
|
|
|
virtual int32_t StartRecordingAudioFile(
|
2012-03-01 18:35:54 +00:00
|
|
|
const char* fileName,
|
2011-07-07 08:21:25 +00:00
|
|
|
const FileFormats format,
|
|
|
|
|
const CodecInst& codecInst,
|
2013-04-09 13:31:37 +00:00
|
|
|
const uint32_t notificationTimeMs = 0,
|
2014-09-11 06:20:28 +00:00
|
|
|
const uint32_t maxSizeBytes = 0) OVERRIDE;
|
2015-03-02 13:07:02 +00:00
|
|
|
|
2014-09-11 06:20:28 +00:00
|
|
|
virtual int32_t StartRecordingAudioStream(
|
2011-07-07 08:21:25 +00:00
|
|
|
OutStream& stream,
|
|
|
|
|
const FileFormats format,
|
|
|
|
|
const CodecInst& codecInst,
|
2014-09-11 06:20:28 +00:00
|
|
|
const uint32_t notificationTimeMs = 0) OVERRIDE;
|
2015-03-02 13:07:02 +00:00
|
|
|
|
2014-09-11 06:20:28 +00:00
|
|
|
virtual int32_t StopRecording() OVERRIDE;
|
2015-03-02 13:07:02 +00:00
|
|
|
|
2014-09-11 06:20:28 +00:00
|
|
|
virtual bool IsRecording() OVERRIDE;
|
2015-03-02 13:07:02 +00:00
|
|
|
|
2014-09-11 06:20:28 +00:00
|
|
|
virtual int32_t RecordDurationMs(uint32_t& durationMs) OVERRIDE;
|
2015-03-02 13:07:02 +00:00
|
|
|
|
2014-09-11 06:20:28 +00:00
|
|
|
virtual bool IsStereo() OVERRIDE;
|
2015-03-02 13:07:02 +00:00
|
|
|
|
2014-09-11 06:20:28 +00:00
|
|
|
virtual int32_t SetModuleFileCallback(FileCallback* callback) OVERRIDE;
|
2015-03-02 13:07:02 +00:00
|
|
|
|
2014-09-11 06:20:28 +00:00
|
|
|
virtual int32_t FileDurationMs(
|
2012-03-01 18:35:54 +00:00
|
|
|
const char* fileName,
|
2013-04-09 13:31:37 +00:00
|
|
|
uint32_t& durationMs,
|
2011-07-07 08:21:25 +00:00
|
|
|
const FileFormats format,
|
2014-09-11 06:20:28 +00:00
|
|
|
const uint32_t freqInHz = 16000) OVERRIDE;
|
2015-03-02 13:07:02 +00:00
|
|
|
|
2014-09-11 06:20:28 +00:00
|
|
|
virtual int32_t codec_info(CodecInst& codecInst) const OVERRIDE;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Returns true if the combination of format and codecInst is valid.
|
|
|
|
|
static bool ValidFileFormat(const FileFormats format,
|
|
|
|
|
const CodecInst* codecInst);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Returns true if the filename is valid
|
2012-03-01 18:35:54 +00:00
|
|
|
static bool ValidFileName(const char* fileName);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-03-02 13:07:02 +00:00
|
|
|
// Returns true if the combination of startPointMs and stopPointMs is valid.
|
2013-04-09 13:31:37 +00:00
|
|
|
static bool ValidFilePositions(const uint32_t startPointMs,
|
|
|
|
|
const uint32_t stopPointMs);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Returns true if frequencyInHz is a supported frequency.
|
2013-04-09 13:31:37 +00:00
|
|
|
static bool ValidFrequency(const uint32_t frequencyInHz);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-09 13:31:37 +00:00
|
|
|
void HandlePlayCallbacks(int32_t bytesRead);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-03-02 13:07:02 +00:00
|
|
|
int32_t StartPlayingStream(
|
|
|
|
|
InStream& stream,
|
|
|
|
|
bool loop,
|
|
|
|
|
const uint32_t notificationTimeMs,
|
|
|
|
|
const FileFormats format,
|
|
|
|
|
const CodecInst* codecInst,
|
|
|
|
|
const uint32_t startPointMs,
|
|
|
|
|
const uint32_t stopPointMs);
|
|
|
|
|
|
2013-04-09 13:31:37 +00:00
|
|
|
int32_t _id;
|
2011-12-14 17:27:58 +00:00
|
|
|
CriticalSectionWrapper* _crit;
|
|
|
|
|
CriticalSectionWrapper* _callbackCrit;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
ModuleFileUtility* _ptrFileUtilityObj;
|
|
|
|
|
CodecInst codec_info_;
|
|
|
|
|
|
|
|
|
|
InStream* _ptrInStream;
|
|
|
|
|
OutStream* _ptrOutStream;
|
|
|
|
|
|
|
|
|
|
FileFormats _fileFormat;
|
2013-04-09 13:31:37 +00:00
|
|
|
uint32_t _recordDurationMs;
|
|
|
|
|
uint32_t _playoutPositionMs;
|
|
|
|
|
uint32_t _notificationMs;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
bool _playingActive;
|
|
|
|
|
bool _recordingActive;
|
|
|
|
|
bool _isStereo;
|
|
|
|
|
bool _openFile;
|
|
|
|
|
|
2012-03-01 18:35:54 +00:00
|
|
|
char _fileName[512];
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
FileCallback* _ptrCallback;
|
|
|
|
|
};
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#endif // WEBRTC_MODULES_MEDIA_FILE_SOURCE_MEDIA_FILE_IMPL_H_
|