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_INTERFACE_FILE_PLAYER_H_ 12 #define WEBRTC_MODULES_UTILITY_INTERFACE_FILE_PLAYER_H_ 13 14 #include "webrtc/common_types.h" 15 #include "webrtc/common_video/interface/i420_video_frame.h" 16 #include "webrtc/engine_configurations.h" 17 #include "webrtc/modules/interface/module_common_types.h" 18 #include "webrtc/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. 32 static FilePlayer* CreateFilePlayer(const uint32_t instanceID, 33 const FileFormats fileFormat); 34 35 static void DestroyFilePlayer(FilePlayer* player); 36 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; 44 45 // Register callback for receiving file playing notifications. 46 virtual int32_t RegisterModuleFileCallback( 47 FileCallback* callback) = 0; 48 49 // API for playing audio from fileName to channel. 50 // Note: codecInst is used for pre-encoded files. 51 virtual int32_t StartPlayingFile( 52 const char* fileName, 53 bool loop, 54 uint32_t startPosition, 55 float volumeScaling, 56 uint32_t notification, 57 uint32_t stopPosition = 0, 58 const CodecInst* codecInst = NULL) = 0; 59 60 // Note: codecInst is used for pre-encoded files. 61 virtual int32_t StartPlayingFile( 62 InStream& sourceStream, 63 uint32_t startPosition, 64 float volumeScaling, 65 uint32_t notification, 66 uint32_t stopPosition = 0, 67 const CodecInst* codecInst = NULL) = 0; 68 69 virtual int32_t StopPlayingFile() = 0; 70 71 virtual bool IsPlayingFile() const = 0; 72 73 virtual int32_t GetPlayoutPosition(uint32_t& durationMs) = 0; 74 75 // Set audioCodec to the currently used audio codec. 76 virtual int32_t AudioCodec(CodecInst& audioCodec) const = 0; 77 78 virtual int32_t Frequency() const = 0; 79 80 // Note: scaleFactor is in the range [0.0 - 2.0] 81 virtual int32_t SetAudioScaling(float scaleFactor) = 0; 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. 87 virtual int32_t TimeUntilNextVideoFrame() { return -1;} 88 89 virtual int32_t StartPlayingVideoFile( 90 const char* /*fileName*/, 91 bool /*loop*/, 92 bool /*videoOnly*/) { return -1;} 93 94 virtual int32_t video_codec_info(VideoCodec& /*videoCodec*/) const 95 {return -1;} 96 97 virtual int32_t GetVideoFromFile(I420VideoFrame& /*videoFrame*/) 98 { return -1;} 99 100 // Same as GetVideoFromFile(). videoFrame will have the resolution specified 101 // by the width outWidth and height outHeight in pixels. 102 virtual int32_t GetVideoFromFile(I420VideoFrame& /*videoFrame*/, 103 const uint32_t /*outWidth*/, 104 const uint32_t /*outHeight*/) 105 {return -1;} 106 protected: 107 virtual ~FilePlayer() {} 108 109 }; 110 } // namespace webrtc 111 #endif // WEBRTC_MODULES_UTILITY_INTERFACE_FILE_PLAYER_H_ 112