Revert of Set defaultPageScaleLimits before setIgnoreViewportTagScaleLimits (patchset...
[chromium-blink-merge.git] / media / filters / decoder_selector.h
blobd13eb9be3e11c0ddbb47332313ad9a1873400ebe
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);
75 private:
76 void DecryptingDecoderInitDone(PipelineStatus status);
77 void DecryptingDemuxerStreamInitDone(PipelineStatus status);
78 void InitializeDecoder();
79 void DecoderInitDone(PipelineStatus status);
80 void ReturnNullDecoder();
82 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
83 ScopedVector<Decoder> decoders_;
85 DemuxerStream* input_stream_;
86 SetDecryptorReadyCB set_decryptor_ready_cb_;
87 SelectDecoderCB select_decoder_cb_;
88 typename Decoder::OutputCB output_cb_;
90 scoped_ptr<Decoder> decoder_;
91 scoped_ptr<DecryptingDemuxerStream> decrypted_stream_;
93 // NOTE: Weak pointers must be invalidated before all other member variables.
94 base::WeakPtrFactory<DecoderSelector> weak_ptr_factory_;
96 DISALLOW_IMPLICIT_CONSTRUCTORS(DecoderSelector);
99 typedef DecoderSelector<DemuxerStream::VIDEO> VideoDecoderSelector;
100 typedef DecoderSelector<DemuxerStream::AUDIO> AudioDecoderSelector;
102 } // namespace media
104 #endif // MEDIA_FILTERS_DECODER_SELECTOR_H_