Exclude TrayIMETest.PerformActionOnDetailedView under valgrind, where it crashes.
[chromium-blink-merge.git] / media / filters / decoder_selector.h
blob26973067c0a6dbe192193bb21e5e5975b174901b
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;
26 class MediaLog;
28 // DecoderSelector (creates if necessary and) initializes the proper
29 // Decoder for a given DemuxerStream. If the given DemuxerStream is
30 // encrypted, a DecryptingDemuxerStream may also be created.
31 // The template parameter |StreamType| is the type of stream we will be
32 // selecting a decoder for.
33 template<DemuxerStream::Type StreamType>
34 class MEDIA_EXPORT DecoderSelector {
35 public:
36 typedef DecoderStreamTraits<StreamType> StreamTraits;
37 typedef typename StreamTraits::DecoderType Decoder;
39 // Indicates completion of Decoder selection.
40 // - First parameter: The initialized Decoder. If it's set to NULL, then
41 // Decoder initialization failed.
42 // - Second parameter: The initialized DecryptingDemuxerStream. If it's not
43 // NULL, then a DecryptingDemuxerStream is created and initialized to do
44 // decryption for the initialized Decoder.
45 // Note: The caller owns selected Decoder and DecryptingDemuxerStream.
46 // The caller should call DecryptingDemuxerStream::Reset() before
47 // calling Decoder::Reset() to release any pending decryption or read.
48 typedef base::Callback<
49 void(scoped_ptr<Decoder>,
50 scoped_ptr<DecryptingDemuxerStream>)>
51 SelectDecoderCB;
53 // |decoders| contains the Decoders to use when initializing.
54 DecoderSelector(
55 const scoped_refptr<base::SingleThreadTaskRunner>& message_loop,
56 ScopedVector<Decoder> decoders,
57 const scoped_refptr<MediaLog>& media_log);
59 // Aborts pending Decoder selection and fires |select_decoder_cb| with
60 // NULL and NULL immediately if it's pending.
61 ~DecoderSelector();
63 // Initializes and selects the first Decoder that can decode the |stream|.
64 // The selected Decoder (and DecryptingDemuxerStream) is returned via
65 // the |select_decoder_cb|.
66 // Notes:
67 // 1. This must not be called again before |select_decoder_cb| is run.
68 // 2. Decoders that fail to initialize will be deleted. Future calls will
69 // select from the decoders following the decoder that was last returned.
70 // 3. |set_decryptor_ready_cb| is optional. If |set_decryptor_ready_cb| is
71 // null, no decryptor will be available to perform decryption.
72 void SelectDecoder(DemuxerStream* stream,
73 const SetDecryptorReadyCB& set_decryptor_ready_cb,
74 const SelectDecoderCB& select_decoder_cb,
75 const typename Decoder::OutputCB& output_cb,
76 const base::Closure& waiting_for_decryption_key_cb);
78 private:
79 void DecryptingDecoderInitDone(bool success);
80 void DecryptingDemuxerStreamInitDone(PipelineStatus status);
81 void InitializeDecoder();
82 void DecoderInitDone(bool success);
83 void ReturnNullDecoder();
85 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
86 ScopedVector<Decoder> decoders_;
87 scoped_refptr<MediaLog> media_log_;
89 DemuxerStream* input_stream_;
90 SetDecryptorReadyCB set_decryptor_ready_cb_;
91 SelectDecoderCB select_decoder_cb_;
92 typename Decoder::OutputCB output_cb_;
93 base::Closure waiting_for_decryption_key_cb_;
95 scoped_ptr<Decoder> decoder_;
96 scoped_ptr<DecryptingDemuxerStream> decrypted_stream_;
98 // NOTE: Weak pointers must be invalidated before all other member variables.
99 base::WeakPtrFactory<DecoderSelector> weak_ptr_factory_;
101 DISALLOW_IMPLICIT_CONSTRUCTORS(DecoderSelector);
104 typedef DecoderSelector<DemuxerStream::VIDEO> VideoDecoderSelector;
105 typedef DecoderSelector<DemuxerStream::AUDIO> AudioDecoderSelector;
107 } // namespace media
109 #endif // MEDIA_FILTERS_DECODER_SELECTOR_H_