Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROMECAST_MEDIA_CMA_BASE_BUFFERING_FRAME_PROVIDER_H_ | |
| 6 #define CHROMECAST_MEDIA_CMA_BASE_BUFFERING_FRAME_PROVIDER_H_ | |
| 7 | |
| 8 #include <list> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/threading/thread_checker.h" | |
| 14 #include "chromecast/media/cma/base/coded_frame_provider.h" | |
| 15 #include "media/base/audio_decoder_config.h" | |
| 16 #include "media/base/video_decoder_config.h" | |
| 17 | |
| 18 namespace chromecast { | |
| 19 namespace media { | |
| 20 class DecoderBufferBase; | |
| 21 | |
| 22 // BufferingFrameProvider - | |
| 23 // Fetch some data from another CodedFrameProvider up to a certain size limit. | |
| 24 // | |
|
gunsch
2014/09/09 15:58:19
remove
damienv1
2014/09/09 16:24:17
Done.
| |
| 25 class BufferingFrameProvider : public CodedFrameProvider { | |
| 26 public: | |
| 27 typedef base::Callback<void(const scoped_refptr<DecoderBufferBase>&, bool)> | |
| 28 FrameBufferedCB; | |
| 29 | |
| 30 // Create a frame provider that buffers coded frames up to the | |
|
gunsch
2014/09/09 15:58:19
nit: Creates
damienv1
2014/09/09 16:24:17
Done.
| |
| 31 // |max_buffer_size| limit (given as a number of bytes). | |
| 32 // |max_frame_size| corresponds to an upper bound of the expected frame size. | |
| 33 // Each time a frame is buffered, |frame_buffered_cb| is invoked with the | |
| 34 // last frame buffered. The second parameter of the callback indicates | |
| 35 // whether the maximum capacity has been reached, i.e. whether the next frame | |
| 36 // size might overflow the buffer: |total_buffer_size_| + next_frame_size | |
| 37 // might be greater than |max_buffer_size|. | |
| 38 // Note: takes ownership of |coded_frame_provider|. | |
| 39 BufferingFrameProvider( | |
| 40 scoped_ptr<CodedFrameProvider> coded_frame_provider, | |
| 41 size_t max_buffer_size, | |
| 42 size_t max_frame_size, | |
| 43 const FrameBufferedCB& frame_buffered_cb); | |
| 44 virtual ~BufferingFrameProvider(); | |
| 45 | |
| 46 // CodedFrameProvider implementation. | |
| 47 virtual void Read(const ReadCB& read_cb) OVERRIDE; | |
| 48 virtual void Flush(const base::Closure& flush_cb) OVERRIDE; | |
| 49 | |
| 50 private: | |
| 51 class BufferWithConfig { | |
| 52 public: | |
| 53 BufferWithConfig( | |
| 54 const scoped_refptr<DecoderBufferBase>& buffer, | |
| 55 const ::media::AudioDecoderConfig& audio_config, | |
| 56 const ::media::VideoDecoderConfig& video_config); | |
| 57 ~BufferWithConfig(); | |
| 58 | |
| 59 const scoped_refptr<DecoderBufferBase>& buffer() const { return buffer_; } | |
| 60 const ::media::AudioDecoderConfig& audio_config() const { | |
| 61 return audio_config_; | |
| 62 } | |
| 63 const ::media::VideoDecoderConfig& video_config() const { | |
| 64 return video_config_; | |
| 65 } | |
| 66 | |
| 67 private: | |
| 68 scoped_refptr<DecoderBufferBase> buffer_; | |
| 69 ::media::AudioDecoderConfig audio_config_; | |
| 70 ::media::VideoDecoderConfig video_config_; | |
| 71 }; | |
| 72 | |
| 73 void OnNewBuffer(const scoped_refptr<DecoderBufferBase>& buffer, | |
| 74 const ::media::AudioDecoderConfig& audio_config, | |
| 75 const ::media::VideoDecoderConfig& video_config); | |
| 76 void RequestBufferIfNeeded(); | |
| 77 void CompleteReadIfNeeded(); | |
| 78 | |
| 79 base::ThreadChecker thread_checker_; | |
| 80 | |
| 81 // Frame provider the buffering frame provider fetches data from. | |
| 82 scoped_ptr<CodedFrameProvider> coded_frame_provider_; | |
| 83 | |
| 84 // Indicate whether there is a pending read request on | |
| 85 // |coded_frame_provider_|. | |
| 86 bool is_pending_request_; | |
| 87 | |
| 88 // Indicate whether the end of stream has been reached. | |
| 89 bool is_eos_; | |
| 90 | |
| 91 std::list<BufferWithConfig> buffer_list_; | |
| 92 | |
| 93 // Size in bytes of audio/video buffers in |buffer_list_|. | |
| 94 size_t total_buffer_size_; | |
| 95 | |
| 96 // Max amount of data to buffer. | |
| 97 // i.e. this is the maximum size of buffers in |buffer_list_|. | |
| 98 const size_t max_buffer_size_; | |
| 99 | |
| 100 // Maximum expected frame size. | |
| 101 const size_t max_frame_size_; | |
| 102 | |
| 103 // Callback invoked each time there is a new frame buffered. | |
| 104 FrameBufferedCB frame_buffered_cb_; | |
| 105 | |
| 106 // Pending read callback. | |
| 107 ReadCB read_cb_; | |
| 108 | |
| 109 scoped_ptr<base::WeakPtrFactory<BufferingFrameProvider> > weak_factory_; | |
|
gunsch
2014/09/09 15:58:19
It seems to be more typical to have a member base:
damienv1
2014/09/09 16:24:17
This one is a special case since I have to re-crea
| |
| 110 base::WeakPtr<BufferingFrameProvider> weak_this_; | |
| 111 | |
| 112 DISALLOW_COPY_AND_ASSIGN(BufferingFrameProvider); | |
| 113 }; | |
| 114 | |
| 115 } // namespace media | |
| 116 } // namespace chromecast | |
| 117 | |
| 118 #endif // CHROMECAST_MEDIA_CMA_BASE_BUFFERING_FRAME_PROVIDER_H_ | |
| OLD | NEW |