Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(753)

Side by Side Diff: media/filters/video_frame_stream.h

Issue 16274005: Separate DemuxerStream and VideoDecoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: GVD: return drained frames before starting over Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_FILTERS_VIDEO_FRAME_STREAM_H_ 5 #ifndef MEDIA_FILTERS_VIDEO_FRAME_STREAM_H_
6 #define MEDIA_FILTERS_VIDEO_FRAME_STREAM_H_ 6 #define MEDIA_FILTERS_VIDEO_FRAME_STREAM_H_
7 7
8 #include <list>
9
10 #include "base/basictypes.h" 8 #include "base/basictypes.h"
11 #include "base/callback.h" 9 #include "base/callback.h"
12 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
15 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
16 #include "media/base/decryptor.h" 14 #include "media/base/decryptor.h"
17 #include "media/base/demuxer_stream.h" 15 #include "media/base/demuxer_stream.h"
18 #include "media/base/media_export.h" 16 #include "media/base/media_export.h"
19 #include "media/base/pipeline_status.h" 17 #include "media/base/pipeline_status.h"
20 #include "media/base/video_decoder.h" 18 #include "media/base/video_decoder.h"
21 19
20 #include "media/base/video_decoder_config.h"
scherkus (not reviewing) 2013/07/09 01:18:39 fix to remove whitespace / remove include if not n
xhwang 2013/07/09 20:00:04 Done.
21
22 namespace base { 22 namespace base {
23 class MessageLoopProxy; 23 class MessageLoopProxy;
24 } 24 }
25 25
26 namespace media { 26 namespace media {
27 27
28 class DecryptingDemuxerStream; 28 class DecryptingDemuxerStream;
29 class VideoDecoderSelector; 29 class VideoDecoderSelector;
30 30
31 // Wraps a DemuxerStream and a list of VideoDecoders and provides decoded 31 // Wraps a DemuxerStream and a list of VideoDecoders and provides decoded
32 // VideoFrames to its client (e.g. VideoRendererBase). 32 // VideoFrames to its client (e.g. VideoRendererBase).
33 class MEDIA_EXPORT VideoFrameStream : public DemuxerStream { 33 class MEDIA_EXPORT VideoFrameStream {
34 public: 34 public:
35 // Indicates completion of VideoFrameStream initialization. 35 // Indicates completion of VideoFrameStream initialization.
36 typedef base::Callback<void(bool success, bool has_alpha)> InitCB; 36 typedef base::Callback<void(bool success, bool has_alpha)> InitCB;
37 37
38 VideoFrameStream(const scoped_refptr<base::MessageLoopProxy>& message_loop, 38 VideoFrameStream(const scoped_refptr<base::MessageLoopProxy>& message_loop,
39 ScopedVector<VideoDecoder> decoders, 39 ScopedVector<VideoDecoder> decoders,
40 const SetDecryptorReadyCB& set_decryptor_ready_cb); 40 const SetDecryptorReadyCB& set_decryptor_ready_cb);
41 virtual ~VideoFrameStream(); 41 virtual ~VideoFrameStream();
42 42
43 // Initializes the VideoFrameStream and returns the initialization result 43 // Initializes the VideoFrameStream and returns the initialization result
44 // through |init_cb|. Note that |init_cb| is always called asynchronously. 44 // through |init_cb|. Note that |init_cb| is always called asynchronously.
45 void Initialize(DemuxerStream* stream, 45 void Initialize(DemuxerStream* stream,
46 const StatisticsCB& statistics_cb, 46 const StatisticsCB& statistics_cb,
47 const InitCB& init_cb); 47 const InitCB& init_cb);
48 48
49 // Reads a decoded VideoFrame and returns it via the |read_cb|. Note that 49 // Reads a decoded VideoFrame and returns it via the |read_cb|. Note that
50 // |read_cb| is always called asynchronously. This method should only be 50 // |read_cb| is always called asynchronously. This method should only be
51 // called after initialization has succeeded and must not be called during 51 // called after initialization has succeeded and must not be called during
52 // any pending Reset() and/or Stop(). 52 // any pending Reset() and/or Stop().
53 // TODO(xhwang): Rename this back to Read().
53 void ReadFrame(const VideoDecoder::ReadCB& read_cb); 54 void ReadFrame(const VideoDecoder::ReadCB& read_cb);
54 55
55 // Resets the decoder, flushes all decoded frames and/or internal buffers, 56 // Resets the decoder, flushes all decoded frames and/or internal buffers,
56 // fires any existing pending read callback and calls |closure| on completion. 57 // fires any existing pending read callback and calls |closure| on completion.
57 // Note that |closure| is always called asynchronously. This method should 58 // Note that |closure| is always called asynchronously. This method should
58 // only be called after initialization has succeeded and must not be called 59 // only be called after initialization has succeeded and must not be called
59 // during any pending Reset() and/or Stop(). 60 // during any pending Reset() and/or Stop().
60 void Reset(const base::Closure& closure); 61 void Reset(const base::Closure& closure);
61 62
62 // Stops the decoder, fires any existing pending read callback or reset 63 // Stops the decoder, fires any existing pending read callback or reset
63 // callback and calls |closure| on completion. Note that |closure| is always 64 // callback and calls |closure| on completion. Note that |closure| is always
64 // called asynchronously. The VideoFrameStream cannot be used anymore after 65 // called asynchronously. The VideoFrameStream cannot be used anymore after
65 // it is stopped. This method can be called at any time but not during another 66 // it is stopped. This method can be called at any time but not during another
66 // pending Stop(). 67 // pending Stop().
67 void Stop(const base::Closure& closure); 68 void Stop(const base::Closure& closure);
68 69
69 // Returns true if the decoder currently has the ability to decode and return 70 // Returns true if the decoder currently has the ability to decode and return
70 // a VideoFrame. 71 // a VideoFrame.
71 bool CanReadWithoutStalling() const; 72 bool CanReadWithoutStalling() const;
72 73
73 // DemuxerStream implementation.
74 virtual void Read(const ReadCB& read_cb) OVERRIDE;
75 virtual AudioDecoderConfig audio_decoder_config() OVERRIDE;
76 virtual VideoDecoderConfig video_decoder_config() OVERRIDE;
77 virtual Type type() OVERRIDE;
78 virtual void EnableBitstreamConverter() OVERRIDE;
79
80 private: 74 private:
81 enum State { 75 enum State {
82 STATE_UNINITIALIZED, 76 STATE_UNINITIALIZED,
83 STATE_INITIALIZING, 77 STATE_INITIALIZING,
84 STATE_NORMAL, 78 STATE_NORMAL, // Includes idle, pending decoder decode/reset/stop.
85 STATE_FLUSHING_DECODER, 79 STATE_FLUSHING_DECODER,
80 STATE_PENDING_DEMUXER_READ,
86 STATE_REINITIALIZING_DECODER, 81 STATE_REINITIALIZING_DECODER,
87 STATE_STOPPED, 82 STATE_STOPPED,
88 STATE_ERROR 83 STATE_ERROR
89 }; 84 };
90 85
91 // Called when |decoder_selector| selected the |selected_decoder|. 86 // Called when |decoder_selector| selected the |selected_decoder|.
92 // |decrypting_demuxer_stream| was also populated if a DecryptingDemuxerStream 87 // |decrypting_demuxer_stream| was also populated if a DecryptingDemuxerStream
93 // is created to help decrypt the encrypted stream. 88 // is created to help decrypt the encrypted stream.
94 void OnDecoderSelected( 89 void OnDecoderSelected(
95 scoped_ptr<VideoDecoder> selected_decoder, 90 scoped_ptr<VideoDecoder> selected_decoder,
96 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream); 91 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream);
97 92
98 // Callback for VideoDecoder::Read(). 93 // Satisfy pending |read_cb_| with |status| and |frame|.
94 void SatisfyRead(VideoDecoder::Status status,
95 const scoped_refptr<VideoFrame>& frame);
96
97 // Abort pending |read_cb_|.
98 void AbortRead();
99
100 // Decodes |buffer| and returns the result via OnFrameReady().
101 void Decode(const scoped_refptr<DecoderBuffer>& buffer);
102
103 // Flushes the decoder with an EOS buffer to retrieve internally buffered
104 // video frames.
105 void FlushDecoder();
106
107 // Callback for VideoDecoder::Decode().
99 void OnFrameReady(const VideoDecoder::Status status, 108 void OnFrameReady(const VideoDecoder::Status status,
100 const scoped_refptr<VideoFrame>& frame); 109 const scoped_refptr<VideoFrame>& frame);
101 110
111 // Reads a buffer from |stream_| and returns the result via OnBufferReady().
112 void ReadFromDemuxerStream();
113
102 // Callback for DemuxerStream::Read(). 114 // Callback for DemuxerStream::Read().
103 void OnBufferReady(const DemuxerStream::ReadCB& demuxer_read_cb, 115 void OnBufferReady(DemuxerStream::Status status,
104 DemuxerStream::Status status,
105 const scoped_refptr<DecoderBuffer>& buffer); 116 const scoped_refptr<DecoderBuffer>& buffer);
106 117
107 void ReinitializeDecoder(); 118 void ReinitializeDecoder();
108 119
109 // Callback for VideoDecoder reinitialization. 120 // Callback for VideoDecoder reinitialization.
110 void OnDecoderReinitialized(PipelineStatus status); 121 void OnDecoderReinitialized(PipelineStatus status);
111 122
112 void ResetDecoder(); 123 void ResetDecoder();
113 void OnDecoderReset(); 124 void OnDecoderReset();
114 125
(...skipping 20 matching lines...) Expand all
135 // These two will be set by VideoDecoderSelector::SelectVideoDecoder(). 146 // These two will be set by VideoDecoderSelector::SelectVideoDecoder().
136 scoped_ptr<VideoDecoder> decoder_; 147 scoped_ptr<VideoDecoder> decoder_;
137 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream_; 148 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream_;
138 149
139 DISALLOW_COPY_AND_ASSIGN(VideoFrameStream); 150 DISALLOW_COPY_AND_ASSIGN(VideoFrameStream);
140 }; 151 };
141 152
142 } // namespace media 153 } // namespace media
143 154
144 #endif // MEDIA_FILTERS_VIDEO_FRAME_STREAM_H_ 155 #endif // MEDIA_FILTERS_VIDEO_FRAME_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698