Home | History | Annotate | Download | only in source
      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_SOURCE_FILE_PLAYER_IMPL_H_
     12 #define WEBRTC_MODULES_UTILITY_SOURCE_FILE_PLAYER_IMPL_H_
     13 
     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"
     24 
     25 namespace webrtc {
     26 class VideoCoder;
     27 class FrameScaler;
     28 
     29 class FilePlayerImpl : public FilePlayer
     30 {
     31 public:
     32     FilePlayerImpl(uint32_t instanceID, FileFormats fileFormat);
     33     ~FilePlayerImpl();
     34 
     35     virtual int Get10msAudioFromFile(
     36         int16_t* outBuffer,
     37         int& lengthInSamples,
     38         int frequencyInHz);
     39     virtual int32_t RegisterModuleFileCallback(FileCallback* callback);
     40     virtual int32_t StartPlayingFile(
     41         const char* fileName,
     42         bool loop,
     43         uint32_t startPosition,
     44         float volumeScaling,
     45         uint32_t notification,
     46         uint32_t stopPosition = 0,
     47         const CodecInst* codecInst = NULL);
     48     virtual int32_t StartPlayingFile(
     49         InStream& sourceStream,
     50         uint32_t startPosition,
     51         float volumeScaling,
     52         uint32_t notification,
     53         uint32_t stopPosition = 0,
     54         const CodecInst* codecInst = NULL);
     55     virtual int32_t StopPlayingFile();
     56     virtual bool IsPlayingFile() const;
     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);
     61 
     62 protected:
     63     int32_t SetUpAudioDecoder();
     64 
     65     uint32_t _instanceID;
     66     const FileFormats _fileFormat;
     67     MediaFile& _fileModule;
     68 
     69     uint32_t _decodedLengthInMS;
     70 
     71 private:
     72     AudioCoder _audioDecoder;
     73 
     74     CodecInst _codec;
     75     int32_t _numberOf10MsPerFrame;
     76     int32_t _numberOf10MsInDecoder;
     77 
     78     Resampler _resampler;
     79     float _scaling;
     80 };
     81 
     82 #ifdef WEBRTC_MODULE_UTILITY_VIDEO
     83 class VideoFilePlayerImpl: public FilePlayerImpl
     84 {
     85 public:
     86     VideoFilePlayerImpl(uint32_t instanceID, FileFormats fileFormat);
     87     ~VideoFilePlayerImpl();
     88 
     89     // FilePlayer functions.
     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);
    100 
    101 private:
    102     int32_t SetUpVideoDecoder();
    103 
    104     scoped_ptr<VideoCoder> video_decoder_;
    105     VideoCodec video_codec_info_;
    106     int32_t _decodedVideoFrames;
    107 
    108     EncodedVideoData& _encodedData;
    109 
    110     FrameScaler& _frameScaler;
    111     CriticalSectionWrapper* _critSec;
    112     TickTime _startTime;
    113     int64_t _accumulatedRenderTimeMs;
    114     uint32_t _frameLengthMS;
    115 
    116     int32_t _numberOfFramesRead;
    117     bool _videoOnly;
    118 };
    119 #endif //WEBRTC_MODULE_UTILITY_VIDEO
    120 
    121 }  // namespace webrtc
    122 #endif // WEBRTC_MODULES_UTILITY_SOURCE_FILE_PLAYER_IMPL_H_
    123