andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1 | /* |
| 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 Kjellander | 273352e | 2015-11-16 10:12:24 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_MEDIA_FILE_MEDIA_FILE_IMPL_H_ |
| 12 | #define WEBRTC_MODULES_MEDIA_FILE_MEDIA_FILE_IMPL_H_ |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 13 | |
pbos@webrtc.org | 3eba48c | 2013-07-16 13:05:40 | [diff] [blame] | 14 | #include "webrtc/common_types.h" |
Henrik Kjellander | 36a14b5 | 2015-11-04 07:31:52 | [diff] [blame] | 15 | #include "webrtc/modules/include/module_common_types.h" |
Henrik Kjellander | 273352e | 2015-11-16 10:12:24 | [diff] [blame] | 16 | #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 Lemur | 76de83e | 2017-07-06 17:44:34 | [diff] [blame] | 19 | #include "webrtc/rtc_base/criticalsection.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | class MediaFileImpl : public MediaFile |
| 23 | { |
| 24 | |
| 25 | public: |
pbos@webrtc.org | 283c29a | 2013-04-09 13:31:37 | [diff] [blame] | 26 | MediaFileImpl(const int32_t id); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 27 | ~MediaFileImpl(); |
| 28 | |
pbos | 36df4c4 | 2016-02-25 12:50:01 | [diff] [blame] | 29 | void Process() override; |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 30 | int64_t TimeUntilNextProcess() override; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 31 | |
| 32 | // MediaFile functions |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 33 | int32_t PlayoutAudioData(int8_t* audioBuffer, |
| 34 | size_t& dataLengthInBytes) override; |
andresp@webrtc.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 35 | |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 36 | int32_t PlayoutStereoData(int8_t* audioBufferLeft, |
| 37 | int8_t* audioBufferRight, |
| 38 | size_t& dataLengthInBytes) override; |
andresp@webrtc.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 39 | |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 40 | int32_t StartPlayingAudioFile( |
| 41 | const char* fileName, |
pbos@webrtc.org | 283c29a | 2013-04-09 13:31:37 | [diff] [blame] | 42 | const uint32_t notificationTimeMs = 0, |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 43 | const bool loop = false, |
| 44 | const FileFormats format = kFileFormatPcm16kHzFile, |
| 45 | const CodecInst* codecInst = NULL, |
pbos@webrtc.org | 283c29a | 2013-04-09 13:31:37 | [diff] [blame] | 46 | const uint32_t startPointMs = 0, |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 47 | const uint32_t stopPointMs = 0) override; |
andresp@webrtc.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 48 | |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 49 | int32_t StartPlayingAudioStream( |
| 50 | InStream& stream, |
pbos@webrtc.org | 283c29a | 2013-04-09 13:31:37 | [diff] [blame] | 51 | const uint32_t notificationTimeMs = 0, |
| 52 | const FileFormats format = kFileFormatPcm16kHzFile, |
| 53 | const CodecInst* codecInst = NULL, |
| 54 | const uint32_t startPointMs = 0, |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 55 | const uint32_t stopPointMs = 0) override; |
andresp@webrtc.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 56 | |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 57 | int32_t StopPlaying() override; |
andresp@webrtc.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 58 | |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 59 | bool IsPlaying() override; |
andresp@webrtc.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 60 | |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 61 | int32_t PlayoutPositionMs(uint32_t& positionMs) const override; |
andresp@webrtc.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 62 | |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 63 | int32_t IncomingAudioData(const int8_t* audioBuffer, |
| 64 | const size_t bufferLength) override; |
andresp@webrtc.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 65 | |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 66 | 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.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 71 | |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 72 | int32_t StartRecordingAudioStream( |
| 73 | OutStream& stream, |
| 74 | const FileFormats format, |
| 75 | const CodecInst& codecInst, |
| 76 | const uint32_t notificationTimeMs = 0) override; |
andresp@webrtc.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 77 | |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 78 | int32_t StopRecording() override; |
andresp@webrtc.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 79 | |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 80 | bool IsRecording() override; |
andresp@webrtc.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 81 | |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 82 | int32_t RecordDurationMs(uint32_t& durationMs) override; |
andresp@webrtc.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 83 | |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 84 | bool IsStereo() override; |
andresp@webrtc.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 85 | |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 86 | int32_t SetModuleFileCallback(FileCallback* callback) override; |
andresp@webrtc.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 87 | |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 88 | int32_t FileDurationMs(const char* fileName, |
| 89 | uint32_t& durationMs, |
| 90 | const FileFormats format, |
| 91 | const uint32_t freqInHz = 16000) override; |
andresp@webrtc.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 92 | |
kjellander@webrtc.org | 860ac53 | 2015-03-04 12:58:35 | [diff] [blame] | 93 | int32_t codec_info(CodecInst& codecInst) const override; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 94 | |
| 95 | private: |
| 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.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 104 | // Returns true if the combination of startPointMs and stopPointMs is valid. |
pbos@webrtc.org | 283c29a | 2013-04-09 13:31:37 | [diff] [blame] | 105 | static bool ValidFilePositions(const uint32_t startPointMs, |
| 106 | const uint32_t stopPointMs); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 107 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 108 | // Returns true if frequencyInHz is a supported frequency. |
pbos@webrtc.org | 283c29a | 2013-04-09 13:31:37 | [diff] [blame] | 109 | static bool ValidFrequency(const uint32_t frequencyInHz); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 110 | |
pbos@webrtc.org | 283c29a | 2013-04-09 13:31:37 | [diff] [blame] | 111 | void HandlePlayCallbacks(int32_t bytesRead); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 112 | |
andresp@webrtc.org | 51bd14d | 2015-03-02 13:07:02 | [diff] [blame] | 113 | 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.org | 283c29a | 2013-04-09 13:31:37 | [diff] [blame] | 122 | int32_t _id; |
kthelgason | 118284a | 2017-03-30 08:14:41 | [diff] [blame] | 123 | rtc::CriticalSection _crit; |
| 124 | rtc::CriticalSection _callbackCrit; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 125 | |
| 126 | ModuleFileUtility* _ptrFileUtilityObj; |
| 127 | CodecInst codec_info_; |
| 128 | |
| 129 | InStream* _ptrInStream; |
| 130 | OutStream* _ptrOutStream; |
| 131 | |
| 132 | FileFormats _fileFormat; |
pbos@webrtc.org | 283c29a | 2013-04-09 13:31:37 | [diff] [blame] | 133 | uint32_t _recordDurationMs; |
| 134 | uint32_t _playoutPositionMs; |
| 135 | uint32_t _notificationMs; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 136 | |
| 137 | bool _playingActive; |
| 138 | bool _recordingActive; |
| 139 | bool _isStereo; |
| 140 | bool _openFile; |
| 141 | |
| 142 | char _fileName[512]; |
| 143 | |
| 144 | FileCallback* _ptrCallback; |
| 145 | }; |
pbos@webrtc.org | 3b89e10 | 2013-07-03 15:12:26 | [diff] [blame] | 146 | } // namespace webrtc |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 147 | |
Henrik Kjellander | 273352e | 2015-11-16 10:12:24 | [diff] [blame] | 148 | #endif // WEBRTC_MODULES_MEDIA_FILE_MEDIA_FILE_IMPL_H_ |