Correct gfx dependency for cast_receiver_app.
[chromium-blink-merge.git] / media / filters / decoder_selector.h
blob59c90f57644926817e2c94c2ba75d7d8bf7bedf4
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"
17 namespace base {
18 class SingleThreadTaskRunner;
21 namespace media {
23 class DecoderBuffer;
24 class DecryptingDemuxerStream;
25 class Decryptor;
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 {
34 public:
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>)>
50 SelectDecoderCB;
52 // |decoders| contains the Decoders to use when initializing.
53 DecoderSelector(
54 const scoped_refptr<base::SingleThreadTaskRunner>& message_loop,
55 ScopedVector<Decoder> decoders);
57 // Aborts pending Decoder selection and fires |select_decoder_cb| with
58 // NULL and NULL immediately if it's pending.
59 ~DecoderSelector();
61 // Initializes and selects the first Decoder that can decode the |stream|.
62 // The selected Decoder (and DecryptingDemuxerStream) is returned via
63 // the |select_decoder_cb|.
64 // Notes:
65 // 1. This must not be called again before |select_decoder_cb| is run.
66 // 2. Decoders that fail to initialize will be deleted. Future calls will
67 // select from the decoders following the decoder that was last returned.
68 // 3. |set_decryptor_ready_cb| is optional. If |set_decryptor_ready_cb| is
69 // null, no decryptor will be available to perform decryption.
70 void SelectDecoder(DemuxerStream* stream,
71 const SetDecryptorReadyCB& set_decryptor_ready_cb,
72 const SelectDecoderCB& select_decoder_cb,
73 const typename Decoder::OutputCB& output_cb,
74 const base::Closure& waiting_for_decryption_key_cb);
76 private:
77 void DecryptingDecoderInitDone(PipelineStatus status);
78 void DecryptingDemuxerStreamInitDone(PipelineStatus status);
79 void InitializeDecoder();
80 void DecoderInitDone(PipelineStatus status);
81 void ReturnNullDecoder();
83 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
84 ScopedVector<Decoder> decoders_;
86 DemuxerStream* input_stream_;
87 SetDecryptorReadyCB set_decryptor_ready_cb_;
88 SelectDecoderCB select_decoder_cb_;
89 typename Decoder::OutputCB output_cb_;
90 base::Closure waiting_for_decryption_key_cb_;
92 scoped_ptr<Decoder> decoder_;
93 scoped_ptr<DecryptingDemuxerStream> decrypted_stream_;
95 // NOTE: Weak pointers must be invalidated before all other member variables.
96 base::WeakPtrFactory<DecoderSelector> weak_ptr_factory_;
98 DISALLOW_IMPLICIT_CONSTRUCTORS(DecoderSelector);
101 typedef DecoderSelector<DemuxerStream::VIDEO> VideoDecoderSelector;
102 typedef DecoderSelector<DemuxerStream::AUDIO> AudioDecoderSelector;
104 } // namespace media
106 #endif // MEDIA_FILTERS_DECODER_SELECTOR_H_