| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_BASE_MEDIA_RESOURCE_H_ | 5 #ifndef MEDIA_BASE_MEDIA_RESOURCE_H_ |
| 6 #define MEDIA_BASE_MEDIA_RESOURCE_H_ | 6 #define MEDIA_BASE_MEDIA_RESOURCE_H_ |
| 7 | 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/callback.h" |
| 8 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/time/time.h" |
| 9 #include "media/base/demuxer_stream.h" | 13 #include "media/base/demuxer_stream.h" |
| 10 #include "media/base/media_export.h" | 14 #include "media/base/media_export.h" |
| 11 #include "media/base/media_url_params.h" | 15 #include "media/base/media_url_params.h" |
| 12 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 13 | 17 |
| 14 namespace media { | 18 namespace media { |
| 15 | 19 |
| 20 // The callback that is used to notify clients about streams being enabled and |
| 21 // disabled. The first parameter is the DemuxerStream whose status changed. The |
| 22 // second parameter is a bool indicating whether the stream got enabled or |
| 23 // disabled. The third parameter specifies the media playback position at the |
| 24 // time the status change happened. |
| 25 using StreamStatusChangeCB = |
| 26 base::RepeatingCallback<void(DemuxerStream*, bool, base::TimeDelta)>; |
| 27 |
| 16 // Abstract class that defines how to retrieve "media resources" in | 28 // Abstract class that defines how to retrieve "media resources" in |
| 17 // DemuxerStream form (for most cases) or URL form (for the MediaPlayerRenderer | 29 // DemuxerStream form (for most cases) or URL form (for the MediaPlayerRenderer |
| 18 // case). | 30 // case). |
| 19 // | 31 // |
| 20 // The derived classes must return a non-null value for the getter method | 32 // The derived classes must return a non-null value for the getter method |
| 21 // associated with their type, and return a null/empty value for other getters. | 33 // associated with their type, and return a null/empty value for other getters. |
| 22 class MEDIA_EXPORT MediaResource { | 34 class MEDIA_EXPORT MediaResource { |
| 23 public: | 35 public: |
| 24 enum Type { | 36 enum Type { |
| 25 STREAM, // Indicates GetStreams() should be used | 37 STREAM, // Indicates GetAllStreams() or GetFirstStream() should be used |
| 26 URL, // Indicates GetUrl() should be used | 38 URL, // Indicates GetUrl() should be used |
| 27 }; | 39 }; |
| 28 | 40 |
| 29 MediaResource(); | 41 MediaResource(); |
| 30 virtual ~MediaResource(); | 42 virtual ~MediaResource(); |
| 31 | 43 |
| 44 virtual MediaResource::Type GetType() const; |
| 45 |
| 32 // For Type::STREAM: | 46 // For Type::STREAM: |
| 33 // Returns the first stream of the given stream type (which is not allowed | 47 // Returns a collection of available DemuxerStream objects. |
| 34 // to be DemuxerStream::TEXT), or NULL if that type of stream is not | |
| 35 // present. | |
| 36 // NOTE: Once a DemuxerStream pointer is returned from GetStream it is | 48 // NOTE: Once a DemuxerStream pointer is returned from GetStream it is |
| 37 // guaranteed to stay valid for as long as the Demuxer/MediaResource | 49 // guaranteed to stay valid for as long as the Demuxer/MediaResource |
| 38 // is alive. But make no assumption that once GetStream returned a non-null | 50 // is alive. But make no assumption that once GetStream returned a non-null |
| 39 // pointer for some stream type then all subsequent calls will also return | 51 // pointer for some stream type then all subsequent calls will also return |
| 40 // non-null pointer for the same stream type. In MSE Javascript code can | 52 // non-null pointer for the same stream type. In MSE Javascript code can |
| 41 // remove SourceBuffer from a MediaSource at any point and this will make | 53 // remove SourceBuffer from a MediaSource at any point and this will make |
| 42 // some previously existing streams inaccessible/unavailable. | 54 // some previously existing streams inaccessible/unavailable. |
| 43 // Other types: | 55 virtual std::vector<DemuxerStream*> GetAllStreams() = 0; |
| 44 // Should not be called. | 56 |
| 45 virtual DemuxerStream* GetStream(DemuxerStream::Type type) = 0; | 57 // A helper function that return the first stream of the given |type| if one |
| 58 // exists or a null pointer if there is no streams of that type. |
| 59 DemuxerStream* GetFirstStream(DemuxerStream::Type type); |
| 60 |
| 61 // The StreamStatusChangeCB allows clients to receive notifications about one |
| 62 // of the streams being disabled or enabled. |
| 63 virtual void SetStreamStatusChangeCB(const StreamStatusChangeCB& cb) = 0; |
| 46 | 64 |
| 47 // For Type::URL: | 65 // For Type::URL: |
| 48 // Returns the URL parameters of the media to play. Empty URLs are legal, | 66 // Returns the URL parameters of the media to play. Empty URLs are legal, |
| 49 // and should be handled appropriately by the caller. | 67 // and should be handled appropriately by the caller. |
| 50 // Other types: | 68 // Other types: |
| 51 // Should not be called. | 69 // Should not be called. |
| 52 virtual MediaUrlParams GetMediaUrlParams() const; | 70 virtual MediaUrlParams GetMediaUrlParams() const; |
| 53 | 71 |
| 54 virtual MediaResource::Type GetType() const; | |
| 55 | |
| 56 private: | 72 private: |
| 57 DISALLOW_COPY_AND_ASSIGN(MediaResource); | 73 DISALLOW_COPY_AND_ASSIGN(MediaResource); |
| 58 }; | 74 }; |
| 59 | 75 |
| 60 } // namespace media | 76 } // namespace media |
| 61 | 77 |
| 62 #endif // MEDIA_BASE_MEDIA_RESOURCE_H_ | 78 #endif // MEDIA_BASE_MEDIA_RESOURCE_H_ |
| OLD | NEW |