blob: 664030a0f1a8bae6c35e226eb861f8252667b39e [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:231/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
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 Kjellander273352e2015-11-16 10:12:2411#ifndef WEBRTC_MODULES_MEDIA_FILE_MEDIA_FILE_IMPL_H_
12#define WEBRTC_MODULES_MEDIA_FILE_MEDIA_FILE_IMPL_H_
andrew@webrtc.orgb015cbe2012-10-22 18:19:2313
pbos@webrtc.org3eba48c2013-07-16 13:05:4014#include "webrtc/common_types.h"
Henrik Kjellander36a14b52015-11-04 07:31:5215#include "webrtc/modules/include/module_common_types.h"
Henrik Kjellander273352e2015-11-16 10:12:2416#include "webrtc/modules/media_file/media_file.h"
17#include "webrtc/modules/media_file/media_file_defines.h"
18#include "webrtc/modules/media_file/media_file_utility.h"
Edward Lemur76de83e2017-07-06 17:44:3419#include "webrtc/rtc_base/criticalsection.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:2320
21namespace webrtc {
22class MediaFileImpl : public MediaFile
23{
24
25public:
pbos@webrtc.org283c29a2013-04-09 13:31:3726 MediaFileImpl(const int32_t id);
andrew@webrtc.orgb015cbe2012-10-22 18:19:2327 ~MediaFileImpl();
28
pbos36df4c42016-02-25 12:50:0129 void Process() override;
kjellander@webrtc.org860ac532015-03-04 12:58:3530 int64_t TimeUntilNextProcess() override;
andrew@webrtc.orgb015cbe2012-10-22 18:19:2331
32 // MediaFile functions
kjellander@webrtc.org860ac532015-03-04 12:58:3533 int32_t PlayoutAudioData(int8_t* audioBuffer,
34 size_t& dataLengthInBytes) override;
andresp@webrtc.org51bd14d2015-03-02 13:07:0235
kjellander@webrtc.org860ac532015-03-04 12:58:3536 int32_t PlayoutStereoData(int8_t* audioBufferLeft,
37 int8_t* audioBufferRight,
38 size_t& dataLengthInBytes) override;
andresp@webrtc.org51bd14d2015-03-02 13:07:0239
kjellander@webrtc.org860ac532015-03-04 12:58:3540 int32_t StartPlayingAudioFile(
41 const char* fileName,
pbos@webrtc.org283c29a2013-04-09 13:31:3742 const uint32_t notificationTimeMs = 0,
kjellander@webrtc.org860ac532015-03-04 12:58:3543 const bool loop = false,
44 const FileFormats format = kFileFormatPcm16kHzFile,
45 const CodecInst* codecInst = NULL,
pbos@webrtc.org283c29a2013-04-09 13:31:3746 const uint32_t startPointMs = 0,
kjellander@webrtc.org860ac532015-03-04 12:58:3547 const uint32_t stopPointMs = 0) override;
andresp@webrtc.org51bd14d2015-03-02 13:07:0248
kjellander@webrtc.org860ac532015-03-04 12:58:3549 int32_t StartPlayingAudioStream(
50 InStream& stream,
pbos@webrtc.org283c29a2013-04-09 13:31:3751 const uint32_t notificationTimeMs = 0,
52 const FileFormats format = kFileFormatPcm16kHzFile,
53 const CodecInst* codecInst = NULL,
54 const uint32_t startPointMs = 0,
kjellander@webrtc.org860ac532015-03-04 12:58:3555 const uint32_t stopPointMs = 0) override;
andresp@webrtc.org51bd14d2015-03-02 13:07:0256
kjellander@webrtc.org860ac532015-03-04 12:58:3557 int32_t StopPlaying() override;
andresp@webrtc.org51bd14d2015-03-02 13:07:0258
kjellander@webrtc.org860ac532015-03-04 12:58:3559 bool IsPlaying() override;
andresp@webrtc.org51bd14d2015-03-02 13:07:0260
kjellander@webrtc.org860ac532015-03-04 12:58:3561 int32_t PlayoutPositionMs(uint32_t& positionMs) const override;
andresp@webrtc.org51bd14d2015-03-02 13:07:0262
kjellander@webrtc.org860ac532015-03-04 12:58:3563 int32_t IncomingAudioData(const int8_t* audioBuffer,
64 const size_t bufferLength) override;
andresp@webrtc.org51bd14d2015-03-02 13:07:0265
kjellander@webrtc.org860ac532015-03-04 12:58:3566 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.org51bd14d2015-03-02 13:07:0271
kjellander@webrtc.org860ac532015-03-04 12:58:3572 int32_t StartRecordingAudioStream(
73 OutStream& stream,
74 const FileFormats format,
75 const CodecInst& codecInst,
76 const uint32_t notificationTimeMs = 0) override;
andresp@webrtc.org51bd14d2015-03-02 13:07:0277
kjellander@webrtc.org860ac532015-03-04 12:58:3578 int32_t StopRecording() override;
andresp@webrtc.org51bd14d2015-03-02 13:07:0279
kjellander@webrtc.org860ac532015-03-04 12:58:3580 bool IsRecording() override;
andresp@webrtc.org51bd14d2015-03-02 13:07:0281
kjellander@webrtc.org860ac532015-03-04 12:58:3582 int32_t RecordDurationMs(uint32_t& durationMs) override;
andresp@webrtc.org51bd14d2015-03-02 13:07:0283
kjellander@webrtc.org860ac532015-03-04 12:58:3584 bool IsStereo() override;
andresp@webrtc.org51bd14d2015-03-02 13:07:0285
kjellander@webrtc.org860ac532015-03-04 12:58:3586 int32_t SetModuleFileCallback(FileCallback* callback) override;
andresp@webrtc.org51bd14d2015-03-02 13:07:0287
kjellander@webrtc.org860ac532015-03-04 12:58:3588 int32_t FileDurationMs(const char* fileName,
89 uint32_t& durationMs,
90 const FileFormats format,
91 const uint32_t freqInHz = 16000) override;
andresp@webrtc.org51bd14d2015-03-02 13:07:0292
kjellander@webrtc.org860ac532015-03-04 12:58:3593 int32_t codec_info(CodecInst& codecInst) const override;
andrew@webrtc.orgb015cbe2012-10-22 18:19:2394
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
102 static bool ValidFileName(const char* fileName);
103
andresp@webrtc.org51bd14d2015-03-02 13:07:02104 // Returns true if the combination of startPointMs and stopPointMs is valid.
pbos@webrtc.org283c29a2013-04-09 13:31:37105 static bool ValidFilePositions(const uint32_t startPointMs,
106 const uint32_t stopPointMs);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23107
andrew@webrtc.orgb015cbe2012-10-22 18:19:23108 // Returns true if frequencyInHz is a supported frequency.
pbos@webrtc.org283c29a2013-04-09 13:31:37109 static bool ValidFrequency(const uint32_t frequencyInHz);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23110
pbos@webrtc.org283c29a2013-04-09 13:31:37111 void HandlePlayCallbacks(int32_t bytesRead);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23112
andresp@webrtc.org51bd14d2015-03-02 13:07:02113 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.org283c29a2013-04-09 13:31:37122 int32_t _id;
kthelgason118284a2017-03-30 08:14:41123 rtc::CriticalSection _crit;
124 rtc::CriticalSection _callbackCrit;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23125
126 ModuleFileUtility* _ptrFileUtilityObj;
127 CodecInst codec_info_;
128
129 InStream* _ptrInStream;
130 OutStream* _ptrOutStream;
131
132 FileFormats _fileFormat;
pbos@webrtc.org283c29a2013-04-09 13:31:37133 uint32_t _recordDurationMs;
134 uint32_t _playoutPositionMs;
135 uint32_t _notificationMs;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23136
137 bool _playingActive;
138 bool _recordingActive;
139 bool _isStereo;
140 bool _openFile;
141
142 char _fileName[512];
143
144 FileCallback* _ptrCallback;
145};
pbos@webrtc.org3b89e102013-07-03 15:12:26146} // namespace webrtc
andrew@webrtc.orgb015cbe2012-10-22 18:19:23147
Henrik Kjellander273352e2015-11-16 10:12:24148#endif // WEBRTC_MODULES_MEDIA_FILE_MEDIA_FILE_IMPL_H_