blob: aae1ae97f378f3a288f1d1a6a081b63cfb669202 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org2559cbf2012-02-27 19:18:25 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.org8b062002013-07-12 08:28:10 +000014#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.com470e71d2011-07-07 08:21:25 +000024
25namespace webrtc {
26class VideoCoder;
27class FrameScaler;
28
29class FilePlayerImpl : public FilePlayer
30{
31public:
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000032 FilePlayerImpl(uint32_t instanceID, FileFormats fileFormat);
niklase@google.com470e71d2011-07-07 08:21:25 +000033 ~FilePlayerImpl();
34
andrew@webrtc.orge59a0ac2012-05-08 17:12:40 +000035 virtual int Get10msAudioFromFile(
36 int16_t* outBuffer,
37 int& lengthInSamples,
38 int frequencyInHz);
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000039 virtual int32_t RegisterModuleFileCallback(FileCallback* callback);
40 virtual int32_t StartPlayingFile(
leozwang@webrtc.org2559cbf2012-02-27 19:18:25 +000041 const char* fileName,
niklase@google.com470e71d2011-07-07 08:21:25 +000042 bool loop,
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000043 uint32_t startPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +000044 float volumeScaling,
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000045 uint32_t notification,
46 uint32_t stopPosition = 0,
niklase@google.com470e71d2011-07-07 08:21:25 +000047 const CodecInst* codecInst = NULL);
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000048 virtual int32_t StartPlayingFile(
niklase@google.com470e71d2011-07-07 08:21:25 +000049 InStream& sourceStream,
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000050 uint32_t startPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +000051 float volumeScaling,
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000052 uint32_t notification,
53 uint32_t stopPosition = 0,
niklase@google.com470e71d2011-07-07 08:21:25 +000054 const CodecInst* codecInst = NULL);
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000055 virtual int32_t StopPlayingFile();
niklase@google.com470e71d2011-07-07 08:21:25 +000056 virtual bool IsPlayingFile() const;
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000057 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.com470e71d2011-07-07 08:21:25 +000061
62protected:
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000063 int32_t SetUpAudioDecoder();
niklase@google.com470e71d2011-07-07 08:21:25 +000064
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000065 uint32_t _instanceID;
niklase@google.com470e71d2011-07-07 08:21:25 +000066 const FileFormats _fileFormat;
67 MediaFile& _fileModule;
68
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000069 uint32_t _decodedLengthInMS;
niklase@google.com470e71d2011-07-07 08:21:25 +000070
71private:
niklase@google.com470e71d2011-07-07 08:21:25 +000072 AudioCoder _audioDecoder;
73
74 CodecInst _codec;
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000075 int32_t _numberOf10MsPerFrame;
76 int32_t _numberOf10MsInDecoder;
niklase@google.com470e71d2011-07-07 08:21:25 +000077
78 Resampler _resampler;
79 float _scaling;
80};
81
82#ifdef WEBRTC_MODULE_UTILITY_VIDEO
83class VideoFilePlayerImpl: public FilePlayerImpl
84{
85public:
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000086 VideoFilePlayerImpl(uint32_t instanceID, FileFormats fileFormat);
niklase@google.com470e71d2011-07-07 08:21:25 +000087 ~VideoFilePlayerImpl();
88
89 // FilePlayer functions.
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +000090 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.com470e71d2011-07-07 08:21:25 +0000100
101private:
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +0000102 int32_t SetUpVideoDecoder();
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
104 VideoCoder& _videoDecoder;
105 VideoCodec video_codec_info_;
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +0000106 int32_t _decodedVideoFrames;
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
108 EncodedVideoData& _encodedData;
109
110 FrameScaler& _frameScaler;
henrike@webrtc.org105e0712011-12-16 19:53:46 +0000111 CriticalSectionWrapper* _critSec;
niklase@google.com470e71d2011-07-07 08:21:25 +0000112 TickTime _startTime;
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +0000113 int64_t _accumulatedRenderTimeMs;
114 uint32_t _frameLengthMS;
niklase@google.com470e71d2011-07-07 08:21:25 +0000115
pbos@webrtc.orgc75102e2013-04-09 13:32:55 +0000116 int32_t _numberOfFramesRead;
niklase@google.com470e71d2011-07-07 08:21:25 +0000117 bool _videoOnly;
118};
119#endif //WEBRTC_MODULE_UTILITY_VIDEO
120
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000121} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000122#endif // WEBRTC_MODULES_UTILITY_SOURCE_FILE_PLAYER_IMPL_H_