Move UpdateManifest test from unit_tests into extensions_unittests.
[chromium-blink-merge.git] / media / base / fake_demuxer_stream.h
blobddb8a46fdfbd7f707295645a1872dc6b31ad71b1
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_BASE_FAKE_DEMUXER_STREAM_H_
6 #define MEDIA_BASE_FAKE_DEMUXER_STREAM_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "media/base/audio_decoder_config.h"
11 #include "media/base/demuxer_stream.h"
12 #include "media/base/demuxer_stream_provider.h"
13 #include "media/base/video_decoder_config.h"
15 namespace base {
16 class SingleThreadTaskRunner;
17 } // namespace base
19 namespace media {
21 class FakeDemuxerStream : public DemuxerStream {
22 public:
23 // Constructs an object that outputs |num_configs| different configs in
24 // sequence with |num_frames_in_one_config| buffers for each config. The
25 // output buffers are encrypted if |is_encrypted| is true.
26 FakeDemuxerStream(int num_configs,
27 int num_buffers_in_one_config,
28 bool is_encrypted);
29 ~FakeDemuxerStream() override;
31 // DemuxerStream implementation.
32 void Read(const ReadCB& read_cb) override;
33 AudioDecoderConfig audio_decoder_config() override;
34 VideoDecoderConfig video_decoder_config() override;
35 Type type() const override;
36 bool SupportsConfigChanges() override;
37 VideoRotation video_rotation() override;
39 void Initialize();
41 int num_buffers_returned() const { return num_buffers_returned_; }
43 // Upon the next read, holds the read callback until SatisfyRead() or Reset()
44 // is called.
45 void HoldNextRead();
47 // Upon the next config change read, holds the read callback until
48 // SatisfyRead() or Reset() is called. If there is no config change any more,
49 // no read will be held.
50 void HoldNextConfigChangeRead();
52 // Satisfies the pending read with the next scheduled status and buffer.
53 void SatisfyRead();
55 // Satisfies pending read request and then holds the following read.
56 void SatisfyReadAndHoldNext();
58 // Satisfies the pending read (if any) with kAborted and NULL. This call
59 // always clears |hold_next_read_|.
60 void Reset();
62 // Reset() this demuxer stream and set the reading position to the start of
63 // the stream.
64 void SeekToStart();
66 // Sets the splice timestamp for all furture buffers returned via Read().
67 void set_splice_timestamp(base::TimeDelta splice_timestamp) {
68 splice_timestamp_ = splice_timestamp;
71 private:
72 void UpdateVideoDecoderConfig();
73 void DoRead();
75 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
77 const int num_configs_;
78 const int num_buffers_in_one_config_;
79 const bool config_changes_;
80 const bool is_encrypted_;
82 int num_configs_left_;
84 // Number of frames left with the current decoder config.
85 int num_buffers_left_in_current_config_;
87 int num_buffers_returned_;
89 base::TimeDelta current_timestamp_;
90 base::TimeDelta duration_;
91 base::TimeDelta splice_timestamp_;
93 gfx::Size next_coded_size_;
94 VideoDecoderConfig video_decoder_config_;
96 ReadCB read_cb_;
98 int next_read_num_;
99 // Zero-based number indicating which read operation should be held. -1 means
100 // no read shall be held.
101 int read_to_hold_;
103 DISALLOW_COPY_AND_ASSIGN(FakeDemuxerStream);
106 class FakeDemuxerStreamProvider : public DemuxerStreamProvider {
107 public:
108 // Note: FakeDemuxerStream currently only supports a fake video DemuxerStream.
109 FakeDemuxerStreamProvider(int num_video_configs,
110 int num_video_buffers_in_one_config,
111 bool is_video_encrypted);
112 ~FakeDemuxerStreamProvider() override;
114 // DemuxerStreamProvider implementation.
115 DemuxerStream* GetStream(DemuxerStream::Type type) override;
117 private:
118 FakeDemuxerStream fake_video_stream_;
120 DISALLOW_COPY_AND_ASSIGN(FakeDemuxerStreamProvider);
123 } // namespace media
125 #endif // MEDIA_BASE_FAKE_DEMUXER_STREAM_H_