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_SOURCE_FILE_PLAYER_IMPL_H_ |
| 12 | #define WEBRTC_MODULES_UTILITY_SOURCE_FILE_PLAYER_IMPL_H_ |
| 13 | |
pbos@webrtc.org | 8b06200 | 2013-07-12 08:28:10 +0000 | [diff] [blame] | 14 | #include "webrtc/common_audio/resampler/include/resampler.h" |
| 15 | #include "webrtc/common_types.h" |
| 16 | #include "webrtc/engine_configurations.h" |
| 17 | #include "webrtc/modules/media_file/interface/media_file.h" |
| 18 | #include "webrtc/modules/media_file/interface/media_file_defines.h" |
| 19 | #include "webrtc/modules/utility/interface/file_player.h" |
| 20 | #include "webrtc/modules/utility/source/coder.h" |
| 21 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 22 | #include "webrtc/system_wrappers/interface/tick_util.h" |
| 23 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
| 26 | class VideoCoder; |
| 27 | class FrameScaler; |
| 28 | |
| 29 | class FilePlayerImpl : public FilePlayer |
| 30 | { |
| 31 | public: |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 32 | FilePlayerImpl(uint32_t instanceID, FileFormats fileFormat); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | ~FilePlayerImpl(); |
| 34 | |
andrew@webrtc.org | e59a0ac | 2012-05-08 17:12:40 +0000 | [diff] [blame] | 35 | virtual int Get10msAudioFromFile( |
| 36 | int16_t* outBuffer, |
| 37 | int& lengthInSamples, |
| 38 | int frequencyInHz); |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 39 | virtual int32_t RegisterModuleFileCallback(FileCallback* callback); |
| 40 | virtual int32_t StartPlayingFile( |
leozwang@webrtc.org | 2559cbf | 2012-02-27 19:18:25 +0000 | [diff] [blame] | 41 | const char* fileName, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | bool loop, |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 43 | uint32_t startPosition, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | float volumeScaling, |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 45 | uint32_t notification, |
| 46 | uint32_t stopPosition = 0, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | const CodecInst* codecInst = NULL); |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 48 | virtual int32_t StartPlayingFile( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | InStream& sourceStream, |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 50 | uint32_t startPosition, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | float volumeScaling, |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 52 | uint32_t notification, |
| 53 | uint32_t stopPosition = 0, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | const CodecInst* codecInst = NULL); |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 55 | virtual int32_t StopPlayingFile(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | virtual bool IsPlayingFile() const; |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 57 | virtual int32_t GetPlayoutPosition(uint32_t& durationMs); |
| 58 | virtual int32_t AudioCodec(CodecInst& audioCodec) const; |
| 59 | virtual int32_t Frequency() const; |
| 60 | virtual int32_t SetAudioScaling(float scaleFactor); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | |
| 62 | protected: |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 63 | int32_t SetUpAudioDecoder(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 65 | uint32_t _instanceID; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | const FileFormats _fileFormat; |
| 67 | MediaFile& _fileModule; |
| 68 | |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 69 | uint32_t _decodedLengthInMS; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | |
| 71 | private: |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | AudioCoder _audioDecoder; |
| 73 | |
| 74 | CodecInst _codec; |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 75 | int32_t _numberOf10MsPerFrame; |
| 76 | int32_t _numberOf10MsInDecoder; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | |
| 78 | Resampler _resampler; |
| 79 | float _scaling; |
| 80 | }; |
| 81 | |
| 82 | #ifdef WEBRTC_MODULE_UTILITY_VIDEO |
| 83 | class VideoFilePlayerImpl: public FilePlayerImpl |
| 84 | { |
| 85 | public: |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 86 | VideoFilePlayerImpl(uint32_t instanceID, FileFormats fileFormat); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | ~VideoFilePlayerImpl(); |
| 88 | |
| 89 | // FilePlayer functions. |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 90 | virtual int32_t TimeUntilNextVideoFrame(); |
| 91 | virtual int32_t StartPlayingVideoFile(const char* fileName, |
| 92 | bool loop, |
| 93 | bool videoOnly); |
| 94 | virtual int32_t StopPlayingFile(); |
| 95 | virtual int32_t video_codec_info(VideoCodec& videoCodec) const; |
| 96 | virtual int32_t GetVideoFromFile(I420VideoFrame& videoFrame); |
| 97 | virtual int32_t GetVideoFromFile(I420VideoFrame& videoFrame, |
| 98 | const uint32_t outWidth, |
| 99 | const uint32_t outHeight); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | |
| 101 | private: |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 102 | int32_t SetUpVideoDecoder(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame^] | 104 | rtc::scoped_ptr<VideoCoder> video_decoder_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 105 | VideoCodec video_codec_info_; |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 106 | int32_t _decodedVideoFrames; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | |
| 108 | EncodedVideoData& _encodedData; |
| 109 | |
| 110 | FrameScaler& _frameScaler; |
henrike@webrtc.org | 105e071 | 2011-12-16 19:53:46 +0000 | [diff] [blame] | 111 | CriticalSectionWrapper* _critSec; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 112 | TickTime _startTime; |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 113 | int64_t _accumulatedRenderTimeMs; |
| 114 | uint32_t _frameLengthMS; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | |
pbos@webrtc.org | c75102e | 2013-04-09 13:32:55 +0000 | [diff] [blame] | 116 | int32_t _numberOfFramesRead; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 117 | bool _videoOnly; |
| 118 | }; |
| 119 | #endif //WEBRTC_MODULE_UTILITY_VIDEO |
| 120 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 121 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | #endif // WEBRTC_MODULES_UTILITY_SOURCE_FILE_PLAYER_IMPL_H_ |