niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | 2559cbf | 2012-02-27 19:18:25 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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" |
mikhal@webrtc.org | 9fedff7 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 15 | #include "common_video/interface/i420_video_frame.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | #include "engine_configurations.h" |
| 17 | #include "module_common_types.h" |
| 18 | #include "typedefs.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 video file formats (e.g. AVI) if the flag |
| 31 | // WEBRTC_MODULE_UTILITY_VIDEO is not defined. |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 32 | static FilePlayer* CreateFilePlayer(const uint32_t instanceID, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | const FileFormats fileFormat); |
| 34 | |
| 35 | static void DestroyFilePlayer(FilePlayer* player); |
| 36 | |
andrew@webrtc.org | e59a0ac | 2012-05-08 17:12:40 +0000 | [diff] [blame] | 37 | // Read 10 ms of audio at |frequencyInHz| to |outBuffer|. |lengthInSamples| |
| 38 | // will be set to the number of samples read (not the number of samples per |
| 39 | // channel). |
| 40 | virtual int Get10msAudioFromFile( |
| 41 | int16_t* outBuffer, |
| 42 | int& lengthInSamples, |
| 43 | int frequencyInHz) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | |
| 45 | // Register callback for receiving file playing notifications. |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 46 | virtual int32_t RegisterModuleFileCallback( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | FileCallback* callback) = 0; |
| 48 | |
| 49 | // API for playing audio from fileName to channel. |
| 50 | // Note: codecInst is used for pre-encoded files. |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 51 | virtual int32_t StartPlayingFile( |
leozwang@webrtc.org | 2559cbf | 2012-02-27 19:18:25 +0000 | [diff] [blame] | 52 | const char* fileName, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | bool loop, |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 54 | uint32_t startPosition, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | float volumeScaling, |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 56 | uint32_t notification, |
| 57 | uint32_t stopPosition = 0, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | const CodecInst* codecInst = NULL) = 0; |
| 59 | |
| 60 | // Note: codecInst is used for pre-encoded files. |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 61 | virtual int32_t StartPlayingFile( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | InStream& sourceStream, |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 63 | uint32_t startPosition, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | float volumeScaling, |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 65 | uint32_t notification, |
| 66 | uint32_t stopPosition = 0, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | const CodecInst* codecInst = NULL) = 0; |
| 68 | |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 69 | virtual int32_t StopPlayingFile() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | |
| 71 | virtual bool IsPlayingFile() const = 0; |
| 72 | |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 73 | virtual int32_t GetPlayoutPosition(uint32_t& durationMs) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | |
| 75 | // Set audioCodec to the currently used audio codec. |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 76 | virtual int32_t AudioCodec(CodecInst& audioCodec) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 78 | virtual int32_t Frequency() const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | |
| 80 | // Note: scaleFactor is in the range [0.0 - 2.0] |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 81 | virtual int32_t SetAudioScaling(float scaleFactor) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | |
| 83 | // Return the time in ms until next video frame should be pulled (by |
| 84 | // calling GetVideoFromFile(..)). |
| 85 | // Note: this API reads one video frame from file. This means that it should |
| 86 | // be called exactly once per GetVideoFromFile(..) API call. |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 87 | virtual int32_t TimeUntilNextVideoFrame() { return -1;} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 88 | |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 89 | virtual int32_t StartPlayingVideoFile( |
leozwang@webrtc.org | 2559cbf | 2012-02-27 19:18:25 +0000 | [diff] [blame] | 90 | const char* /*fileName*/, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | bool /*loop*/, |
| 92 | bool /*videoOnly*/) { return -1;} |
| 93 | |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 94 | virtual int32_t video_codec_info(VideoCodec& /*videoCodec*/) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | {return -1;} |
| 96 | |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 97 | virtual int32_t GetVideoFromFile(I420VideoFrame& /*videoFrame*/) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | { return -1;} |
| 99 | |
| 100 | // Same as GetVideoFromFile(). videoFrame will have the resolution specified |
| 101 | // by the width outWidth and height outHeight in pixels. |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 102 | virtual int32_t GetVideoFromFile(I420VideoFrame& /*videoFrame*/, |
| 103 | const uint32_t /*outWidth*/, |
| 104 | const uint32_t /*outHeight*/) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 105 | {return -1;} |
| 106 | protected: |
| 107 | virtual ~FilePlayer() {} |
| 108 | |
| 109 | }; |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 110 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | #endif // WEBRTC_MODULES_UTILITY_INTERFACE_FILE_PLAYER_H_ |