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.
5 #ifndef MEDIA_FILTERS_DECODER_SELECTOR_H_
6 #define MEDIA_FILTERS_DECODER_SELECTOR_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_vector.h"
11 #include "base/memory/weak_ptr.h"
12 #include "media/base/decryptor.h"
13 #include "media/base/demuxer_stream.h"
14 #include "media/base/pipeline_status.h"
15 #include "media/filters/decoder_stream_traits.h"
18 class SingleThreadTaskRunner
;
24 class DecryptingDemuxerStream
;
27 // DecoderSelector (creates if necessary and) initializes the proper
28 // Decoder for a given DemuxerStream. If the given DemuxerStream is
29 // encrypted, a DecryptingDemuxerStream may also be created.
30 // The template parameter |StreamType| is the type of stream we will be
31 // selecting a decoder for.
32 template<DemuxerStream::Type StreamType
>
33 class MEDIA_EXPORT DecoderSelector
{
35 typedef DecoderStreamTraits
<StreamType
> StreamTraits
;
36 typedef typename
StreamTraits::DecoderType Decoder
;
38 // Indicates completion of Decoder selection.
39 // - First parameter: The initialized Decoder. If it's set to NULL, then
40 // Decoder initialization failed.
41 // - Second parameter: The initialized DecryptingDemuxerStream. If it's not
42 // NULL, then a DecryptingDemuxerStream is created and initialized to do
43 // decryption for the initialized Decoder.
44 // Note: The caller owns selected Decoder and DecryptingDemuxerStream.
45 // The caller should call DecryptingDemuxerStream::Reset() before
46 // calling Decoder::Reset() to release any pending decryption or read.
47 typedef base::Callback
<
48 void(scoped_ptr
<Decoder
>,
49 scoped_ptr
<DecryptingDemuxerStream
>)>
52 // |decoders| contains the Decoders to use when initializing.
54 // |set_decryptor_ready_cb| is optional. If |set_decryptor_ready_cb| is null,
55 // no decryptor will be available to perform decryption.
57 const scoped_refptr
<base::SingleThreadTaskRunner
>& message_loop
,
58 ScopedVector
<Decoder
> decoders
,
59 const SetDecryptorReadyCB
& set_decryptor_ready_cb
);
61 // Aborts pending Decoder selection and fires |select_decoder_cb| with
62 // NULL and NULL immediately if it's pending.
65 // Initializes and selects a Decoder that can decode the |stream|.
66 // Selected Decoder (and DecryptingDemuxerStream) is returned via
67 // the |select_decoder_cb|.
68 void SelectDecoder(DemuxerStream
* stream
,
70 const SelectDecoderCB
& select_decoder_cb
,
71 const typename
Decoder::OutputCB
& output_cb
);
74 void DecryptingDecoderInitDone(PipelineStatus status
);
75 void DecryptingDemuxerStreamInitDone(PipelineStatus status
);
76 void InitializeDecoder();
77 void DecoderInitDone(PipelineStatus status
);
78 void ReturnNullDecoder();
80 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
81 ScopedVector
<Decoder
> decoders_
;
82 SetDecryptorReadyCB set_decryptor_ready_cb_
;
84 DemuxerStream
* input_stream_
;
86 SelectDecoderCB select_decoder_cb_
;
87 typename
Decoder::OutputCB output_cb_
;
89 scoped_ptr
<Decoder
> decoder_
;
90 scoped_ptr
<DecryptingDemuxerStream
> decrypted_stream_
;
92 // NOTE: Weak pointers must be invalidated before all other member variables.
93 base::WeakPtrFactory
<DecoderSelector
> weak_ptr_factory_
;
95 DISALLOW_IMPLICIT_CONSTRUCTORS(DecoderSelector
);
98 typedef DecoderSelector
<DemuxerStream::VIDEO
> VideoDecoderSelector
;
99 typedef DecoderSelector
<DemuxerStream::AUDIO
> AudioDecoderSelector
;
103 #endif // MEDIA_FILTERS_DECODER_SELECTOR_H_