blob: 7d974ef313b7ac0013f074dae0877f62f1677715 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org09e77192012-03-01 18:35:54 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Henrik Kjellander0b9e29c2015-11-16 11:12:24 +010011#ifndef WEBRTC_MODULES_MEDIA_FILE_MEDIA_FILE_IMPL_H_
12#define WEBRTC_MODULES_MEDIA_FILE_MEDIA_FILE_IMPL_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
kthelgason6bfe49c2017-03-30 01:14:41 -070014#include "webrtc/base/criticalsection.h"
pbos@webrtc.org0c4e05a2013-07-16 13:05:40 +000015#include "webrtc/common_types.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010016#include "webrtc/modules/include/module_common_types.h"
Henrik Kjellander0b9e29c2015-11-16 11:12:24 +010017#include "webrtc/modules/media_file/media_file.h"
18#include "webrtc/modules/media_file/media_file_defines.h"
19#include "webrtc/modules/media_file/media_file_utility.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
21namespace webrtc {
22class MediaFileImpl : public MediaFile
23{
24
25public:
pbos@webrtc.org0ea11c12013-04-09 13:31:37 +000026 MediaFileImpl(const int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +000027 ~MediaFileImpl();
28
pbosa26ac922016-02-25 04:50:01 -080029 void Process() override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000030 int64_t TimeUntilNextProcess() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000031
32 // MediaFile functions
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000033 int32_t PlayoutAudioData(int8_t* audioBuffer,
34 size_t& dataLengthInBytes) override;
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +000035
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000036 int32_t PlayoutStereoData(int8_t* audioBufferLeft,
37 int8_t* audioBufferRight,
38 size_t& dataLengthInBytes) override;
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +000039
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000040 int32_t StartPlayingAudioFile(
41 const char* fileName,
pbos@webrtc.org0ea11c12013-04-09 13:31:37 +000042 const uint32_t notificationTimeMs = 0,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000043 const bool loop = false,
44 const FileFormats format = kFileFormatPcm16kHzFile,
45 const CodecInst* codecInst = NULL,
pbos@webrtc.org0ea11c12013-04-09 13:31:37 +000046 const uint32_t startPointMs = 0,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000047 const uint32_t stopPointMs = 0) override;
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +000048
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000049 int32_t StartPlayingAudioStream(
50 InStream& stream,
pbos@webrtc.org0ea11c12013-04-09 13:31:37 +000051 const uint32_t notificationTimeMs = 0,
52 const FileFormats format = kFileFormatPcm16kHzFile,
53 const CodecInst* codecInst = NULL,
54 const uint32_t startPointMs = 0,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000055 const uint32_t stopPointMs = 0) override;
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +000056
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000057 int32_t StopPlaying() override;
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +000058
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000059 bool IsPlaying() override;
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +000060
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000061 int32_t PlayoutPositionMs(uint32_t& positionMs) const override;
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +000062
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000063 int32_t IncomingAudioData(const int8_t* audioBuffer,
64 const size_t bufferLength) override;
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +000065
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000066 int32_t StartRecordingAudioFile(const char* fileName,
67 const FileFormats format,
68 const CodecInst& codecInst,
69 const uint32_t notificationTimeMs = 0,
70 const uint32_t maxSizeBytes = 0) override;
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +000071
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000072 int32_t StartRecordingAudioStream(
73 OutStream& stream,
74 const FileFormats format,
75 const CodecInst& codecInst,
76 const uint32_t notificationTimeMs = 0) override;
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +000077
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000078 int32_t StopRecording() override;
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +000079
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000080 bool IsRecording() override;
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +000081
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000082 int32_t RecordDurationMs(uint32_t& durationMs) override;
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +000083
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000084 bool IsStereo() override;
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +000085
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000086 int32_t SetModuleFileCallback(FileCallback* callback) override;
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +000087
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000088 int32_t FileDurationMs(const char* fileName,
89 uint32_t& durationMs,
90 const FileFormats format,
91 const uint32_t freqInHz = 16000) override;
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +000092
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000093 int32_t codec_info(CodecInst& codecInst) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000094
95private:
96 // Returns true if the combination of format and codecInst is valid.
97 static bool ValidFileFormat(const FileFormats format,
98 const CodecInst* codecInst);
99
100
101 // Returns true if the filename is valid
leozwang@webrtc.org09e77192012-03-01 18:35:54 +0000102 static bool ValidFileName(const char* fileName);
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +0000104 // Returns true if the combination of startPointMs and stopPointMs is valid.
pbos@webrtc.org0ea11c12013-04-09 13:31:37 +0000105 static bool ValidFilePositions(const uint32_t startPointMs,
106 const uint32_t stopPointMs);
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
niklase@google.com470e71d2011-07-07 08:21:25 +0000108 // Returns true if frequencyInHz is a supported frequency.
pbos@webrtc.org0ea11c12013-04-09 13:31:37 +0000109 static bool ValidFrequency(const uint32_t frequencyInHz);
niklase@google.com470e71d2011-07-07 08:21:25 +0000110
pbos@webrtc.org0ea11c12013-04-09 13:31:37 +0000111 void HandlePlayCallbacks(int32_t bytesRead);
niklase@google.com470e71d2011-07-07 08:21:25 +0000112
andresp@webrtc.orge8f50df2015-03-02 13:07:02 +0000113 int32_t StartPlayingStream(
114 InStream& stream,
115 bool loop,
116 const uint32_t notificationTimeMs,
117 const FileFormats format,
118 const CodecInst* codecInst,
119 const uint32_t startPointMs,
120 const uint32_t stopPointMs);
121
pbos@webrtc.org0ea11c12013-04-09 13:31:37 +0000122 int32_t _id;
kthelgason6bfe49c2017-03-30 01:14:41 -0700123 rtc::CriticalSection _crit;
124 rtc::CriticalSection _callbackCrit;
niklase@google.com470e71d2011-07-07 08:21:25 +0000125
126 ModuleFileUtility* _ptrFileUtilityObj;
127 CodecInst codec_info_;
128
129 InStream* _ptrInStream;
130 OutStream* _ptrOutStream;
131
132 FileFormats _fileFormat;
pbos@webrtc.org0ea11c12013-04-09 13:31:37 +0000133 uint32_t _recordDurationMs;
134 uint32_t _playoutPositionMs;
135 uint32_t _notificationMs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000136
137 bool _playingActive;
138 bool _recordingActive;
139 bool _isStereo;
140 bool _openFile;
141
leozwang@webrtc.org09e77192012-03-01 18:35:54 +0000142 char _fileName[512];
niklase@google.com470e71d2011-07-07 08:21:25 +0000143
144 FileCallback* _ptrCallback;
145};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000146} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000147
Henrik Kjellander0b9e29c2015-11-16 11:12:24 +0100148#endif // WEBRTC_MODULES_MEDIA_FILE_MEDIA_FILE_IMPL_H_