demuxer_stream.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright (c) 2012 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_DEMUXER_STREAM_H_
  5. #define MEDIA_BASE_DEMUXER_STREAM_H_
  6. #include "base/callback.h"
  7. #include "base/memory/ref_counted.h"
  8. #include "media/base/media_export.h"
  9. #include "media/base/video_transformation.h"
  10. namespace media {
  11. class AudioDecoderConfig;
  12. class DecoderBuffer;
  13. class VideoDecoderConfig;
  14. enum class StreamLiveness {
  15. kUnknown,
  16. kRecorded,
  17. kLive,
  18. kMaxValue = kLive,
  19. };
  20. MEDIA_EXPORT std::string GetStreamLivenessName(StreamLiveness liveness);
  21. class MEDIA_EXPORT DemuxerStream {
  22. public:
  23. enum Type {
  24. UNKNOWN,
  25. AUDIO,
  26. VIDEO,
  27. TEXT,
  28. TYPE_MAX = TEXT,
  29. };
  30. // Returns a string representation of |type|.
  31. static const char* GetTypeName(Type type);
  32. // Status returned in the Read() callback.
  33. // kOk : Indicates the second parameter is Non-NULL and contains media data
  34. // or the end of the stream.
  35. // kAborted : Indicates an aborted Read(). This can happen if the
  36. // DemuxerStream gets flushed and doesn't have any more data to
  37. // return. The second parameter MUST be NULL when this status is
  38. // returned.
  39. // kConfigChange : Indicates that the AudioDecoderConfig or
  40. // VideoDecoderConfig for the stream has changed.
  41. // The DemuxerStream expects an audio_decoder_config() or
  42. // video_decoder_config() call before Read() will start
  43. // returning DecoderBuffers again. The decoder will need this
  44. // new configuration to properly decode the buffers read
  45. // from this point forward. The second parameter MUST be NULL
  46. // when this status is returned.
  47. // This will only be returned if SupportsConfigChanges()
  48. // returns 'true' for this DemuxerStream.
  49. // kError : Unexpected fatal error happened. Playback should fail.
  50. enum Status {
  51. kOk,
  52. kAborted,
  53. kConfigChanged,
  54. kError,
  55. kStatusMax = kError,
  56. };
  57. static const char* GetStatusName(Status status);
  58. // Request a buffer to returned via the provided callback.
  59. //
  60. // The first parameter indicates the status of the read.
  61. // The second parameter is non-NULL and contains media data
  62. // or the end of the stream if the first parameter is kOk. NULL otherwise.
  63. typedef base::OnceCallback<void(Status, scoped_refptr<DecoderBuffer>)> ReadCB;
  64. virtual void Read(ReadCB read_cb) = 0;
  65. // Returns the audio/video decoder configuration. It is an error to call the
  66. // audio method on a video stream and vice versa. After |kConfigChanged| is
  67. // returned in a Read(), the caller should call this method again to retrieve
  68. // the new config.
  69. virtual AudioDecoderConfig audio_decoder_config() = 0;
  70. virtual VideoDecoderConfig video_decoder_config() = 0;
  71. // Returns the type of stream.
  72. virtual Type type() const = 0;
  73. // Returns liveness of the streams provided, i.e. whether recorded or live.
  74. virtual StreamLiveness liveness() const;
  75. virtual void EnableBitstreamConverter();
  76. // Whether or not this DemuxerStream allows midstream configuration changes.
  77. //
  78. // A DemuxerStream that returns 'true' to this may return the 'kConfigChange'
  79. // status from a Read() call. In this case the client is expected to be
  80. // capable of taking appropriate action to handle config changes. Otherwise
  81. // audio_decoder_config() and video_decoder_config()'s return values are
  82. // guaranteed to remain constant, and the client may make optimizations based
  83. // on this.
  84. virtual bool SupportsConfigChanges() = 0;
  85. protected:
  86. // Only allow concrete implementations to get deleted.
  87. virtual ~DemuxerStream();
  88. };
  89. } // namespace media
  90. #endif // MEDIA_BASE_DEMUXER_STREAM_H_