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
3 // found in the LICENSE file.
5 #ifndef MEDIA_FILTERS_VIDEO_FRAME_STREAM_H_
6 #define MEDIA_FILTERS_VIDEO_FRAME_STREAM_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/memory/weak_ptr.h"
16 #include "media/base/decryptor.h"
17 #include "media/base/demuxer_stream.h"
18 #include "media/base/media_export.h"
19 #include "media/base/pipeline_status.h"
20 #include "media/base/video_decoder.h"
23 class MessageLoopProxy
;
28 class DecryptingDemuxerStream
;
29 class VideoDecoderSelector
;
31 // Wraps a DemuxerStream and a list of VideoDecoders and provides decoded
32 // VideoFrames to its client (e.g. VideoRendererBase).
33 class MEDIA_EXPORT VideoFrameStream
: public DemuxerStream
{
35 // Indicates completion of VideoFrameStream initialization.
36 typedef base::Callback
<void(bool success
, bool has_alpha
)> InitCB
;
38 VideoFrameStream(const scoped_refptr
<base::MessageLoopProxy
>& message_loop
,
39 ScopedVector
<VideoDecoder
> decoders
,
40 const SetDecryptorReadyCB
& set_decryptor_ready_cb
);
41 virtual ~VideoFrameStream();
43 // Initializes the VideoFrameStream and returns the initialization result
44 // through |init_cb|. Note that |init_cb| is always called asynchronously.
45 void Initialize(DemuxerStream
* stream
,
46 const StatisticsCB
& statistics_cb
,
47 const InitCB
& init_cb
);
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
51 // called after initialization has succeeded and must not be called during
52 // any pending Reset() and/or Stop().
53 void ReadFrame(const VideoDecoder::ReadCB
& read_cb
);
55 // Resets the decoder, flushes all decoded frames and/or internal buffers,
56 // fires any existing pending read callback and calls |closure| on completion.
57 // Note that |closure| is always called asynchronously. This method should
58 // only be called after initialization has succeeded and must not be called
59 // during any pending Reset() and/or Stop().
60 void Reset(const base::Closure
& closure
);
62 // Stops the decoder, fires any existing pending read callback or reset
63 // callback and calls |closure| on completion. Note that |closure| is always
64 // 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
67 void Stop(const base::Closure
& closure
);
69 // Returns true if the decoder currently has the ability to decode and return
71 bool HasOutputFrameAvailable() const;
73 // DemuxerStream implementation.
74 virtual void Read(const ReadCB
& read_cb
) OVERRIDE
;
75 virtual const AudioDecoderConfig
& audio_decoder_config() OVERRIDE
;
76 virtual const VideoDecoderConfig
& video_decoder_config() OVERRIDE
;
77 virtual Type
type() OVERRIDE
;
78 virtual void EnableBitstreamConverter() OVERRIDE
;
87 // Called when |decoder_selector| selected the |selected_decoder|.
88 // |decrypting_demuxer_stream| was also populated if a DecryptingDemuxerStream
89 // is created to help decrypt the encrypted stream.
90 void OnDecoderSelected(
91 scoped_ptr
<VideoDecoder
> selected_decoder
,
92 scoped_ptr
<DecryptingDemuxerStream
> decrypting_demuxer_stream
);
94 // Callback for VideoDecoder::Read().
95 void OnFrameRead(const VideoDecoder::Status status
,
96 const scoped_refptr
<VideoFrame
>& frame
);
99 void OnDecoderReset();
102 void OnDecoderStopped();
104 scoped_refptr
<base::MessageLoopProxy
> message_loop_
;
105 base::WeakPtrFactory
<VideoFrameStream
> weak_factory_
;
106 base::WeakPtr
<VideoFrameStream
> weak_this_
;
111 VideoDecoder::ReadCB read_cb_
;
112 base::Closure reset_cb_
;
113 base::Closure stop_cb_
;
115 DemuxerStream
* stream_
;
117 scoped_ptr
<VideoDecoderSelector
> decoder_selector_
;
119 // These two will be set by VideoDecoderSelector::SelectVideoDecoder().
120 scoped_ptr
<VideoDecoder
> decoder_
;
121 scoped_ptr
<DecryptingDemuxerStream
> decrypting_demuxer_stream_
;
123 DISALLOW_COPY_AND_ASSIGN(VideoFrameStream
);
128 #endif // MEDIA_FILTERS_VIDEO_FRAME_STREAM_H_