Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [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 | |
| 11 | #ifndef WEBRTC_MODULES_UTILITY_INCLUDE_FILE_PLAYER_H_ |
| 12 | #define WEBRTC_MODULES_UTILITY_INCLUDE_FILE_PLAYER_H_ |
| 13 | |
| 14 | #include "webrtc/common_types.h" |
| 15 | #include "webrtc/engine_configurations.h" |
| 16 | #include "webrtc/modules/include/module_common_types.h" |
| 17 | #include "webrtc/typedefs.h" |
| 18 | #include "webrtc/video_frame.h" |
| 19 | |
| 20 | namespace webrtc { |
| 21 | class FileCallback; |
| 22 | |
| 23 | class FilePlayer |
| 24 | { |
| 25 | public: |
| 26 | // The largest decoded frame size in samples (60ms with 32kHz sample rate). |
| 27 | enum {MAX_AUDIO_BUFFER_IN_SAMPLES = 60*32}; |
| 28 | enum {MAX_AUDIO_BUFFER_IN_BYTES = MAX_AUDIO_BUFFER_IN_SAMPLES*2}; |
| 29 | |
| 30 | // Note: will return NULL for unsupported formats. |
| 31 | static FilePlayer* CreateFilePlayer(const uint32_t instanceID, |
| 32 | const FileFormats fileFormat); |
| 33 | |
| 34 | static void DestroyFilePlayer(FilePlayer* player); |
| 35 | |
| 36 | // Read 10 ms of audio at |frequencyInHz| to |outBuffer|. |lengthInSamples| |
| 37 | // will be set to the number of samples read (not the number of samples per |
| 38 | // channel). |
| 39 | virtual int Get10msAudioFromFile( |
| 40 | int16_t* outBuffer, |
| 41 | size_t& lengthInSamples, |
| 42 | int frequencyInHz) = 0; |
| 43 | |
| 44 | // Register callback for receiving file playing notifications. |
| 45 | virtual int32_t RegisterModuleFileCallback( |
| 46 | FileCallback* callback) = 0; |
| 47 | |
| 48 | // API for playing audio from fileName to channel. |
| 49 | // Note: codecInst is used for pre-encoded files. |
| 50 | virtual int32_t StartPlayingFile( |
| 51 | const char* fileName, |
| 52 | bool loop, |
| 53 | uint32_t startPosition, |
| 54 | float volumeScaling, |
| 55 | uint32_t notification, |
| 56 | uint32_t stopPosition = 0, |
| 57 | const CodecInst* codecInst = NULL) = 0; |
| 58 | |
| 59 | // Note: codecInst is used for pre-encoded files. |
| 60 | virtual int32_t StartPlayingFile( |
| 61 | InStream& sourceStream, |
| 62 | uint32_t startPosition, |
| 63 | float volumeScaling, |
| 64 | uint32_t notification, |
| 65 | uint32_t stopPosition = 0, |
| 66 | const CodecInst* codecInst = NULL) = 0; |
| 67 | |
| 68 | virtual int32_t StopPlayingFile() = 0; |
| 69 | |
| 70 | virtual bool IsPlayingFile() const = 0; |
| 71 | |
| 72 | virtual int32_t GetPlayoutPosition(uint32_t& durationMs) = 0; |
| 73 | |
| 74 | // Set audioCodec to the currently used audio codec. |
| 75 | virtual int32_t AudioCodec(CodecInst& audioCodec) const = 0; |
| 76 | |
| 77 | virtual int32_t Frequency() const = 0; |
| 78 | |
| 79 | // Note: scaleFactor is in the range [0.0 - 2.0] |
| 80 | virtual int32_t SetAudioScaling(float scaleFactor) = 0; |
| 81 | |
| 82 | // Return the time in ms until next video frame should be pulled (by |
| 83 | // calling GetVideoFromFile(..)). |
| 84 | // Note: this API reads one video frame from file. This means that it should |
| 85 | // be called exactly once per GetVideoFromFile(..) API call. |
| 86 | virtual int32_t TimeUntilNextVideoFrame() { return -1;} |
| 87 | |
| 88 | virtual int32_t StartPlayingVideoFile( |
| 89 | const char* /*fileName*/, |
| 90 | bool /*loop*/, |
| 91 | bool /*videoOnly*/) { return -1;} |
| 92 | |
| 93 | virtual int32_t video_codec_info(VideoCodec& /*videoCodec*/) const |
| 94 | {return -1;} |
| 95 | |
| 96 | virtual int32_t GetVideoFromFile(VideoFrame& /*videoFrame*/) { return -1; } |
| 97 | |
| 98 | // Same as GetVideoFromFile(). videoFrame will have the resolution specified |
| 99 | // by the width outWidth and height outHeight in pixels. |
| 100 | virtual int32_t GetVideoFromFile(VideoFrame& /*videoFrame*/, |
| 101 | const uint32_t /*outWidth*/, |
| 102 | const uint32_t /*outHeight*/) { |
| 103 | return -1; |
| 104 | } |
| 105 | |
| 106 | protected: |
| 107 | virtual ~FilePlayer() {} |
| 108 | |
| 109 | }; |
| 110 | } // namespace webrtc |
| 111 | #endif // WEBRTC_MODULES_UTILITY_INCLUDE_FILE_PLAYER_H_ |