fake_demuxer_stream.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #ifndef MEDIA_BASE_FAKE_DEMUXER_STREAM_H_
  5. #define MEDIA_BASE_FAKE_DEMUXER_STREAM_H_
  6. #include "base/memory/ref_counted.h"
  7. #include "base/time/time.h"
  8. #include "media/base/audio_decoder_config.h"
  9. #include "media/base/demuxer_stream.h"
  10. #include "media/base/media_resource.h"
  11. #include "media/base/video_decoder_config.h"
  12. namespace base {
  13. class SingleThreadTaskRunner;
  14. } // namespace base
  15. namespace media {
  16. class FakeDemuxerStream : public DemuxerStream {
  17. public:
  18. // Constructs an object that outputs |num_configs| different configs in
  19. // sequence with |num_frames_in_one_config| buffers for each config. The
  20. // output buffers are encrypted if |is_encrypted| is true.
  21. FakeDemuxerStream(int num_configs,
  22. int num_buffers_in_one_config,
  23. bool is_encrypted);
  24. // Constructs an object that outputs |num_configs| different configs in
  25. // sequence with |num_frames_in_one_config| buffers for each config. The
  26. // output buffers are encrypted if |is_encrypted| is true.
  27. // The starting config |coded_size| is specified by the
  28. // |start_coded_size| parameter, and each config change increases/decreases it
  29. // by the |coded_size_delta| parameter.
  30. // The returned config always has equal |coded_size| and |visible_rect|
  31. // properties.
  32. FakeDemuxerStream(int num_configs,
  33. int num_buffers_in_one_config,
  34. bool is_encrypted,
  35. gfx::Size start_coded_size,
  36. gfx::Vector2dF coded_size_delta);
  37. FakeDemuxerStream(const FakeDemuxerStream&) = delete;
  38. FakeDemuxerStream& operator=(const FakeDemuxerStream&) = delete;
  39. ~FakeDemuxerStream() override;
  40. // DemuxerStream implementation.
  41. void Read(ReadCB read_cb) override;
  42. AudioDecoderConfig audio_decoder_config() override;
  43. VideoDecoderConfig video_decoder_config() override;
  44. Type type() const override;
  45. bool SupportsConfigChanges() override;
  46. void Initialize();
  47. int num_buffers_returned() const { return num_buffers_returned_; }
  48. // Upon the next read, holds the read callback until SatisfyRead() or Reset()
  49. // is called.
  50. void HoldNextRead();
  51. // Upon the next config change read, holds the read callback until
  52. // SatisfyRead() or Reset() is called. If there is no config change any more,
  53. // no read will be held.
  54. void HoldNextConfigChangeRead();
  55. // Satisfies the pending read with the next scheduled status and buffer.
  56. void SatisfyRead();
  57. // Satisfies pending read request and then holds the following read.
  58. void SatisfyReadAndHoldNext();
  59. // Satisfies the pending read (if any) with kAborted and NULL. This call
  60. // always clears |hold_next_read_|.
  61. void Reset();
  62. // Satisfies the pending read (if any) with kError and NULL. This call
  63. // always clears |hold_next_read_|.
  64. void Error();
  65. // Reset() this demuxer stream and set the reading position to the start of
  66. // the stream.
  67. void SeekToStart();
  68. // Sets further read requests to return EOS buffers.
  69. void SeekToEndOfStream();
  70. base::TimeDelta duration() const { return duration_; }
  71. private:
  72. void UpdateVideoDecoderConfig();
  73. void DoRead();
  74. scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
  75. const int num_configs_;
  76. const int num_buffers_in_one_config_;
  77. const bool config_changes_;
  78. const bool is_encrypted_;
  79. const gfx::Size start_coded_size_;
  80. const gfx::Vector2dF coded_size_delta_;
  81. int num_configs_left_;
  82. // Number of frames left with the current decoder config.
  83. int num_buffers_left_in_current_config_;
  84. int num_buffers_returned_;
  85. base::TimeDelta current_timestamp_;
  86. base::TimeDelta duration_;
  87. gfx::Size next_size_;
  88. VideoDecoderConfig video_decoder_config_;
  89. ReadCB read_cb_;
  90. int next_read_num_;
  91. // Zero-based number indicating which read operation should be held. -1 means
  92. // no read shall be held.
  93. int read_to_hold_;
  94. };
  95. class FakeMediaResource : public MediaResource {
  96. public:
  97. // Note: FakeDemuxerStream currently only supports a fake video DemuxerStream.
  98. FakeMediaResource(int num_video_configs,
  99. int num_video_buffers_in_one_config,
  100. bool is_video_encrypted);
  101. FakeMediaResource(const FakeMediaResource&) = delete;
  102. FakeMediaResource& operator=(const FakeMediaResource&) = delete;
  103. ~FakeMediaResource() override;
  104. // MediaResource implementation.
  105. std::vector<DemuxerStream*> GetAllStreams() override;
  106. private:
  107. FakeDemuxerStream fake_video_stream_;
  108. };
  109. } // namespace media
  110. #endif // MEDIA_BASE_FAKE_DEMUXER_STREAM_H_