| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CONTENT_RENDERER_MEDIA_ANDROID_MEDIA_SOURCE_DELEGATE_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_ANDROID_MEDIA_SOURCE_DELEGATE_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_ANDROID_MEDIA_SOURCE_DELEGATE_H_ | 6 #define CONTENT_RENDERER_MEDIA_ANDROID_MEDIA_SOURCE_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 class RendererDemuxerAndroid; | 40 class RendererDemuxerAndroid; |
| 41 | 41 |
| 42 class MediaSourceDelegate : public media::DemuxerHost { | 42 class MediaSourceDelegate : public media::DemuxerHost { |
| 43 public: | 43 public: |
| 44 typedef base::Callback<void(blink::WebMediaSource*)> | 44 typedef base::Callback<void(blink::WebMediaSource*)> |
| 45 MediaSourceOpenedCB; | 45 MediaSourceOpenedCB; |
| 46 typedef base::Callback<void(blink::WebMediaPlayer::NetworkState)> | 46 typedef base::Callback<void(blink::WebMediaPlayer::NetworkState)> |
| 47 UpdateNetworkStateCB; | 47 UpdateNetworkStateCB; |
| 48 typedef base::Callback<void(const base::TimeDelta&)> DurationChangeCB; | 48 typedef base::Callback<void(const base::TimeDelta&)> DurationChangeCB; |
| 49 | 49 |
| 50 // Helper class used by scoped_ptr to destroy an instance of | |
| 51 // MediaSourceDelegate. | |
| 52 class Destroyer { | |
| 53 public: | |
| 54 inline void operator()(void* media_source_delegate) const { | |
| 55 static_cast<MediaSourceDelegate*>(media_source_delegate)->Destroy(); | |
| 56 } | |
| 57 }; | |
| 58 | |
| 59 MediaSourceDelegate( | 50 MediaSourceDelegate( |
| 60 RendererDemuxerAndroid* demuxer_client, | 51 RendererDemuxerAndroid* demuxer_client, |
| 61 int demuxer_client_id, | 52 int demuxer_client_id, |
| 62 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 53 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 63 const scoped_refptr<media::MediaLog> media_log); | 54 const scoped_refptr<media::MediaLog> media_log); |
| 55 virtual ~MediaSourceDelegate(); |
| 64 | 56 |
| 65 // Initialize the MediaSourceDelegate. |media_source| will be owned by | 57 // Initialize the MediaSourceDelegate. |media_source| will be owned by |
| 66 // this object after this call. | 58 // this object after this call. |
| 67 void InitializeMediaSource( | 59 void InitializeMediaSource( |
| 68 const MediaSourceOpenedCB& media_source_opened_cb, | 60 const MediaSourceOpenedCB& media_source_opened_cb, |
| 69 const media::Demuxer::NeedKeyCB& need_key_cb, | 61 const media::Demuxer::NeedKeyCB& need_key_cb, |
| 70 const media::SetDecryptorReadyCB& set_decryptor_ready_cb, | 62 const media::SetDecryptorReadyCB& set_decryptor_ready_cb, |
| 71 const UpdateNetworkStateCB& update_network_state_cb, | 63 const UpdateNetworkStateCB& update_network_state_cb, |
| 72 const DurationChangeCB& duration_change_cb); | 64 const DurationChangeCB& duration_change_cb); |
| 73 | 65 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 94 // process when this method is called. | 86 // process when this method is called. |
| 95 // If |is_browser_seek| is true, then this is a short-term hack browser | 87 // If |is_browser_seek| is true, then this is a short-term hack browser |
| 96 // seek. | 88 // seek. |
| 97 // TODO(wolenetz): Instead of doing browser seek, browser player should replay | 89 // TODO(wolenetz): Instead of doing browser seek, browser player should replay |
| 98 // cached data since last keyframe. See http://crbug.com/304234. | 90 // cached data since last keyframe. See http://crbug.com/304234. |
| 99 void Seek(const base::TimeDelta& seek_time, bool is_browser_seek); | 91 void Seek(const base::TimeDelta& seek_time, bool is_browser_seek); |
| 100 | 92 |
| 101 // Called when DemuxerStreamPlayer needs to read data from ChunkDemuxer. | 93 // Called when DemuxerStreamPlayer needs to read data from ChunkDemuxer. |
| 102 void OnReadFromDemuxer(media::DemuxerStream::Type type); | 94 void OnReadFromDemuxer(media::DemuxerStream::Type type); |
| 103 | 95 |
| 104 // Called by the Destroyer to destroy an instance of this object. | 96 // Must be called explicitly before |this| can be destroyed. |
| 105 void Destroy(); | 97 void Stop(const base::Closure& stop_cb); |
| 106 | 98 |
| 107 // Called on the main thread to check whether the video stream is encrypted. | 99 // Called on the main thread to check whether the video stream is encrypted. |
| 108 bool IsVideoEncrypted(); | 100 bool IsVideoEncrypted(); |
| 109 | 101 |
| 110 // Gets the ChunkDemuxer timeline offset. | 102 // Gets the ChunkDemuxer timeline offset. |
| 111 base::Time GetTimelineOffset() const; | 103 base::Time GetTimelineOffset() const; |
| 112 | 104 |
| 113 private: | 105 private: |
| 114 // This is private to enforce use of the Destroyer. | |
| 115 virtual ~MediaSourceDelegate(); | |
| 116 | |
| 117 // Methods inherited from DemuxerHost. | 106 // Methods inherited from DemuxerHost. |
| 118 virtual void AddBufferedTimeRange(base::TimeDelta start, | 107 virtual void AddBufferedTimeRange(base::TimeDelta start, |
| 119 base::TimeDelta end) OVERRIDE; | 108 base::TimeDelta end) OVERRIDE; |
| 120 virtual void SetDuration(base::TimeDelta duration) OVERRIDE; | 109 virtual void SetDuration(base::TimeDelta duration) OVERRIDE; |
| 121 virtual void OnDemuxerError(media::PipelineStatus status) OVERRIDE; | 110 virtual void OnDemuxerError(media::PipelineStatus status) OVERRIDE; |
| 122 virtual void AddTextStream(media::DemuxerStream* text_stream, | 111 virtual void AddTextStream(media::DemuxerStream* text_stream, |
| 123 const media::TextTrackConfig& config) OVERRIDE; | 112 const media::TextTrackConfig& config) OVERRIDE; |
| 124 virtual void RemoveTextStream(media::DemuxerStream* text_stream) OVERRIDE; | 113 virtual void RemoveTextStream(media::DemuxerStream* text_stream) OVERRIDE; |
| 125 | 114 |
| 126 // Notifies |demuxer_client_| and fires |duration_changed_cb_|. | 115 // Notifies |demuxer_client_| and fires |duration_changed_cb_|. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 139 | 128 |
| 140 // Callback for ChunkDemuxer::Seek() and callback chain for resetting | 129 // Callback for ChunkDemuxer::Seek() and callback chain for resetting |
| 141 // decrypted audio/video streams if present. | 130 // decrypted audio/video streams if present. |
| 142 // | 131 // |
| 143 // Runs on the media thread. | 132 // Runs on the media thread. |
| 144 void OnDemuxerSeekDone(media::PipelineStatus status); | 133 void OnDemuxerSeekDone(media::PipelineStatus status); |
| 145 void ResetAudioDecryptingDemuxerStream(); | 134 void ResetAudioDecryptingDemuxerStream(); |
| 146 void ResetVideoDecryptingDemuxerStream(); | 135 void ResetVideoDecryptingDemuxerStream(); |
| 147 void FinishResettingDecryptingDemuxerStreams(); | 136 void FinishResettingDecryptingDemuxerStreams(); |
| 148 | 137 |
| 149 // Helper for deleting |this| on the main thread. | |
| 150 void DeleteSelf(); | |
| 151 | |
| 152 void OnDemuxerOpened(); | 138 void OnDemuxerOpened(); |
| 153 void OnNeedKey(const std::string& type, | 139 void OnNeedKey(const std::string& type, |
| 154 const std::vector<uint8>& init_data); | 140 const std::vector<uint8>& init_data); |
| 155 void NotifyDemuxerReady(); | 141 void NotifyDemuxerReady(); |
| 156 | 142 |
| 157 void StopDemuxer(); | 143 // Stops and clears objects on the media thread. |
| 144 void StopDemuxer(const base::Closure& stop_cb); |
| 145 |
| 158 void InitializeDemuxer(); | 146 void InitializeDemuxer(); |
| 159 void SeekInternal(const base::TimeDelta& seek_time); | 147 void SeekInternal(const base::TimeDelta& seek_time); |
| 160 // Reads an access unit from the demuxer stream |stream| and stores it in | 148 // Reads an access unit from the demuxer stream |stream| and stores it in |
| 161 // the |index|th access unit in |params|. | 149 // the |index|th access unit in |params|. |
| 162 void ReadFromDemuxerStream(media::DemuxerStream::Type type, | 150 void ReadFromDemuxerStream(media::DemuxerStream::Type type, |
| 163 scoped_ptr<media::DemuxerData> data, | 151 scoped_ptr<media::DemuxerData> data, |
| 164 size_t index); | 152 size_t index); |
| 165 void OnBufferReady(media::DemuxerStream::Type type, | 153 void OnBufferReady(media::DemuxerStream::Type type, |
| 166 scoped_ptr<media::DemuxerData> data, | 154 scoped_ptr<media::DemuxerData> data, |
| 167 size_t index, | 155 size_t index, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 base::WeakPtrFactory<MediaSourceDelegate> main_weak_factory_; | 229 base::WeakPtrFactory<MediaSourceDelegate> main_weak_factory_; |
| 242 base::WeakPtrFactory<MediaSourceDelegate> media_weak_factory_; | 230 base::WeakPtrFactory<MediaSourceDelegate> media_weak_factory_; |
| 243 base::WeakPtr<MediaSourceDelegate> main_weak_this_; | 231 base::WeakPtr<MediaSourceDelegate> main_weak_this_; |
| 244 | 232 |
| 245 DISALLOW_COPY_AND_ASSIGN(MediaSourceDelegate); | 233 DISALLOW_COPY_AND_ASSIGN(MediaSourceDelegate); |
| 246 }; | 234 }; |
| 247 | 235 |
| 248 } // namespace content | 236 } // namespace content |
| 249 | 237 |
| 250 #endif // CONTENT_RENDERER_MEDIA_ANDROID_MEDIA_SOURCE_DELEGATE_H_ | 238 #endif // CONTENT_RENDERER_MEDIA_ANDROID_MEDIA_SOURCE_DELEGATE_H_ |
| OLD | NEW |