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