Home | History | Annotate | Download | only in filters
      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.
      4 
      5 #ifndef MEDIA_FILTERS_FAKE_DEMUXER_STREAM_H_
      6 #define MEDIA_FILTERS_FAKE_DEMUXER_STREAM_H_
      7 
      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/video_decoder_config.h"
     13 
     14 namespace base {
     15 class SingleThreadTaskRunner;
     16 }  // namespace base
     17 
     18 namespace media {
     19 
     20 class FakeDemuxerStream : public DemuxerStream {
     21  public:
     22   // Constructs an object that outputs |num_configs| different configs in
     23   // sequence with |num_frames_in_one_config| buffers for each config. The
     24   // output buffers are encrypted if |is_encrypted| is true.
     25   FakeDemuxerStream(int num_configs,
     26                     int num_buffers_in_one_config,
     27                     bool is_encrypted);
     28   virtual ~FakeDemuxerStream();
     29 
     30   // DemuxerStream implementation.
     31   virtual void Read(const ReadCB& read_cb) OVERRIDE;
     32   virtual AudioDecoderConfig audio_decoder_config() OVERRIDE;
     33   virtual VideoDecoderConfig video_decoder_config() OVERRIDE;
     34   virtual Type type() OVERRIDE;
     35   virtual void EnableBitstreamConverter() OVERRIDE;
     36   virtual bool SupportsConfigChanges() OVERRIDE;
     37 
     38   void Initialize();
     39 
     40   int num_buffers_returned() const { return num_buffers_returned_; }
     41 
     42   // Upon the next read, holds the read callback until SatisfyRead() or Reset()
     43   // is called.
     44   void HoldNextRead();
     45 
     46   // Upon the next config change read, holds the read callback until
     47   // SatisfyRead() or Reset() is called. If there is no config change any more,
     48   // no read will be held.
     49   void HoldNextConfigChangeRead();
     50 
     51   // Satisfies the pending read with the next scheduled status and buffer.
     52   void SatisfyRead();
     53 
     54   // Satisfies pending read request and then holds the following read.
     55   void SatisfyReadAndHoldNext();
     56 
     57   // Satisfies the pending read (if any) with kAborted and NULL. This call
     58   // always clears |hold_next_read_|.
     59   void Reset();
     60 
     61   // Reset() this demuxer stream and set the reading position to the start of
     62   // the stream.
     63   void SeekToStart();
     64 
     65   // Sets the splice timestamp for all furture buffers returned via Read().
     66   void set_splice_timestamp(base::TimeDelta splice_timestamp) {
     67     splice_timestamp_ = splice_timestamp;
     68   }
     69 
     70  private:
     71   void UpdateVideoDecoderConfig();
     72   void DoRead();
     73 
     74   scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
     75 
     76   const int num_configs_;
     77   const int num_buffers_in_one_config_;
     78   const bool config_changes_;
     79   const bool is_encrypted_;
     80 
     81   int num_configs_left_;
     82 
     83   // Number of frames left with the current decoder config.
     84   int num_buffers_left_in_current_config_;
     85 
     86   int num_buffers_returned_;
     87 
     88   base::TimeDelta current_timestamp_;
     89   base::TimeDelta duration_;
     90   base::TimeDelta splice_timestamp_;
     91 
     92   gfx::Size next_coded_size_;
     93   VideoDecoderConfig video_decoder_config_;
     94 
     95   ReadCB read_cb_;
     96 
     97   int next_read_num_;
     98   // Zero-based number indicating which read operation should be held. -1 means
     99   // no read shall be held.
    100   int read_to_hold_;
    101 
    102   DISALLOW_COPY_AND_ASSIGN(FakeDemuxerStream);
    103 };
    104 
    105 }  // namespace media
    106 
    107 #endif  // MEDIA_FILTERS_FAKE_DEMUXER_STREAM_H_
    108