| 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 "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "media/base/android/demuxer_stream_player_params.h" | |
| 14 #include "media/base/decryptor.h" | 14 #include "media/base/decryptor.h" |
| 15 #include "media/base/demuxer.h" | 15 #include "media/base/demuxer.h" |
| 16 #include "media/base/media_keys.h" | 16 #include "media/base/media_keys.h" |
| 17 #include "media/base/pipeline_status.h" | 17 #include "media/base/pipeline_status.h" |
| 18 #include "media/base/ranges.h" | 18 #include "media/base/ranges.h" |
| 19 #include "media/base/text_track.h" | 19 #include "media/base/text_track.h" |
| 20 #include "third_party/WebKit/public/web/WebMediaPlayer.h" | 20 #include "third_party/WebKit/public/web/WebMediaPlayer.h" |
| 21 | 21 |
| 22 namespace media { | 22 namespace media { |
| 23 class ChunkDemuxer; | 23 class ChunkDemuxer; |
| 24 class DecoderBuffer; | 24 class DecoderBuffer; |
| 25 class DecryptingDemuxerStream; | 25 class DecryptingDemuxerStream; |
| 26 class DemuxerStream; | 26 class DemuxerStream; |
| 27 class MediaLog; | 27 class MediaLog; |
| 28 struct MediaPlayerHostMsg_DemuxerReady_Params; |
| 28 struct MediaPlayerHostMsg_ReadFromDemuxerAck_Params; | 29 struct MediaPlayerHostMsg_ReadFromDemuxerAck_Params; |
| 29 } | 30 } |
| 30 | 31 |
| 31 namespace content { | 32 namespace content { |
| 32 | 33 |
| 33 class WebMediaPlayerProxyAndroid; | 34 class WebMediaPlayerProxyAndroid; |
| 34 | 35 |
| 35 class MediaSourceDelegate : public media::DemuxerHost { | 36 class MediaSourceDelegate : public media::DemuxerHost { |
| 36 public: | 37 public: |
| 37 typedef base::Callback<void(WebKit::WebMediaPlayer::NetworkState)> | 38 typedef base::Callback<void(WebKit::WebMediaPlayer::NetworkState)> |
| 38 UpdateNetworkStateCB; | 39 UpdateNetworkStateCB; |
| 39 typedef base::Callback<void(const base::TimeDelta&)> DurationChangeCB; | 40 typedef base::Callback<void(const base::TimeDelta&)> DurationChangeCB; |
| 40 | 41 |
| 41 // Helper class used by scoped_ptr to destroy an instance of | 42 // Helper class used by scoped_ptr to destroy an instance of |
| 42 // MediaSourceDelegate. | 43 // MediaSourceDelegate. |
| 43 class Destroyer { | 44 class Destroyer { |
| 44 public: | 45 public: |
| 45 inline void operator()(void* media_source_delegate) const { | 46 inline void operator()(void* media_source_delegate) const { |
| 46 static_cast<MediaSourceDelegate*>(media_source_delegate)->Destroy(); | 47 static_cast<MediaSourceDelegate*>(media_source_delegate)->Destroy(); |
| 47 } | 48 } |
| 48 }; | 49 }; |
| 49 | 50 |
| 50 MediaSourceDelegate(WebMediaPlayerProxyAndroid* proxy, | 51 MediaSourceDelegate(WebMediaPlayerProxyAndroid* proxy, |
| 51 int player_id, | 52 int player_id, |
| 53 const scoped_refptr<base::MessageLoopProxy>& media_loop, |
| 52 media::MediaLog* media_log); | 54 media::MediaLog* media_log); |
| 53 | 55 |
| 54 // Initialize the MediaSourceDelegate. |media_source| will be owned by | 56 // Initialize the MediaSourceDelegate. |media_source| will be owned by |
| 55 // this object after this call. | 57 // this object after this call. |
| 56 void InitializeMediaSource( | 58 void InitializeMediaSource( |
| 57 WebKit::WebMediaSource* media_source, | 59 WebKit::WebMediaSource* media_source, |
| 58 const media::NeedKeyCB& need_key_cb, | 60 const media::NeedKeyCB& need_key_cb, |
| 59 const media::SetDecryptorReadyCB& set_decryptor_ready_cb, | 61 const media::SetDecryptorReadyCB& set_decryptor_ready_cb, |
| 60 const UpdateNetworkStateCB& update_network_state_cb, | 62 const UpdateNetworkStateCB& update_network_state_cb, |
| 61 const DurationChangeCB& duration_change_cb); | 63 const DurationChangeCB& duration_change_cb); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 82 // Called when DemuxerStreamPlayer needs to read data from ChunkDemuxer. | 84 // Called when DemuxerStreamPlayer needs to read data from ChunkDemuxer. |
| 83 void OnReadFromDemuxer(media::DemuxerStream::Type type); | 85 void OnReadFromDemuxer(media::DemuxerStream::Type type); |
| 84 | 86 |
| 85 // Called when the player needs the new config data from ChunkDemuxer. | 87 // Called when the player needs the new config data from ChunkDemuxer. |
| 86 void OnMediaConfigRequest(); | 88 void OnMediaConfigRequest(); |
| 87 | 89 |
| 88 // Called by the Destroyer to destroy an instance of this object. | 90 // Called by the Destroyer to destroy an instance of this object. |
| 89 void Destroy(); | 91 void Destroy(); |
| 90 | 92 |
| 91 private: | 93 private: |
| 94 typedef base::Callback<void( |
| 95 scoped_ptr<media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params> params)> |
| 96 ReadFromDemuxerAckCB; |
| 97 typedef base::Callback<void( |
| 98 scoped_ptr<media::MediaPlayerHostMsg_DemuxerReady_Params> params)> |
| 99 DemuxerReadyCB; |
| 100 |
| 92 // This is private to enforce use of the Destroyer. | 101 // This is private to enforce use of the Destroyer. |
| 93 virtual ~MediaSourceDelegate(); | 102 virtual ~MediaSourceDelegate(); |
| 94 | 103 |
| 95 // Methods inherited from DemuxerHost. | 104 // Methods inherited from DemuxerHost. |
| 96 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; | 105 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; |
| 97 virtual void AddBufferedByteRange(int64 start, int64 end) OVERRIDE; | 106 virtual void AddBufferedByteRange(int64 start, int64 end) OVERRIDE; |
| 98 virtual void AddBufferedTimeRange(base::TimeDelta start, | 107 virtual void AddBufferedTimeRange(base::TimeDelta start, |
| 99 base::TimeDelta end) OVERRIDE; | 108 base::TimeDelta end) OVERRIDE; |
| 100 virtual void SetDuration(base::TimeDelta duration) OVERRIDE; | 109 virtual void SetDuration(base::TimeDelta duration) OVERRIDE; |
| 101 virtual void OnDemuxerError(media::PipelineStatus status) OVERRIDE; | 110 virtual void OnDemuxerError(media::PipelineStatus status) OVERRIDE; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 131 void OnDemuxerOpened(); | 140 void OnDemuxerOpened(); |
| 132 void OnNeedKey(const std::string& type, | 141 void OnNeedKey(const std::string& type, |
| 133 const std::string& session_id, | 142 const std::string& session_id, |
| 134 scoped_ptr<uint8[]> init_data, | 143 scoped_ptr<uint8[]> init_data, |
| 135 int init_data_size); | 144 int init_data_size); |
| 136 scoped_ptr<media::TextTrack> OnAddTextTrack(media::TextKind kind, | 145 scoped_ptr<media::TextTrack> OnAddTextTrack(media::TextKind kind, |
| 137 const std::string& label, | 146 const std::string& label, |
| 138 const std::string& language); | 147 const std::string& language); |
| 139 void NotifyDemuxerReady(); | 148 void NotifyDemuxerReady(); |
| 140 bool CanNotifyDemuxerReady(); | 149 bool CanNotifyDemuxerReady(); |
| 150 void SendDemuxerReady( |
| 151 scoped_ptr<media::MediaPlayerHostMsg_DemuxerReady_Params> params); |
| 141 | 152 |
| 153 void StopDemuxer(); |
| 154 void InitializeDemuxer(); |
| 155 void SeekInternal(base::TimeDelta time, unsigned seek_request_id); |
| 156 void OnReadFromDemuxerInternal(media::DemuxerStream::Type type); |
| 142 // Reads an access unit from the demuxer stream |stream| and stores it in | 157 // Reads an access unit from the demuxer stream |stream| and stores it in |
| 143 // the |index|th access unit in |params|. | 158 // the |index|th access unit in |params|. |
| 144 void ReadFromDemuxerStream( | 159 void ReadFromDemuxerStream( |
| 145 media::DemuxerStream::Type type, | 160 media::DemuxerStream::Type type, |
| 146 media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params* params, | 161 scoped_ptr<media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params> params, |
| 147 size_t index); | 162 size_t index); |
| 148 void OnBufferReady( | 163 void OnBufferReady( |
| 149 media::DemuxerStream::Type type, | 164 media::DemuxerStream::Type type, |
| 150 media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params* params, | 165 scoped_ptr<media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params> params, |
| 151 size_t index, | 166 size_t index, |
| 152 media::DemuxerStream::Status status, | 167 media::DemuxerStream::Status status, |
| 153 const scoped_refptr<media::DecoderBuffer>& buffer); | 168 const scoped_refptr<media::DecoderBuffer>& buffer); |
| 154 | 169 |
| 170 void SendReadFromDemuxerAck( |
| 171 scoped_ptr<media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params> params); |
| 172 |
| 155 // Helper function for calculating duration. | 173 // Helper function for calculating duration. |
| 156 int GetDurationMs(); | 174 int GetDurationMs(); |
| 157 | 175 |
| 158 bool HasEncryptedStream(); | 176 bool HasEncryptedStream(); |
| 159 | 177 |
| 160 base::WeakPtrFactory<MediaSourceDelegate> weak_this_; | 178 void SetSeeking(bool seeking); |
| 179 bool IsSeeking() const; |
| 180 |
| 181 // Weak pointer must be dereferenced and invalidated on the same thread. |
| 182 base::WeakPtrFactory<MediaSourceDelegate> main_weak_this_; |
| 183 base::WeakPtrFactory<MediaSourceDelegate> media_weak_this_; |
| 184 |
| 185 // Message loop for main renderer thread. |
| 186 const scoped_refptr<base::MessageLoopProxy> main_loop_; |
| 187 #if defined(GOOGLE_TV) |
| 188 // Message loop for the media thread. |
| 189 // When there is high load in the render thread, the reading from |demuxer_| |
| 190 // and its read-callback loops run very slowly. To improve the response time |
| 191 // of the readings, we run tasks related to |demuxer_| in the media thread. |
| 192 const scoped_refptr<base::MessageLoopProxy> media_loop_; |
| 193 |
| 194 ReadFromDemuxerAckCB send_read_from_demuxer_ack_cb_; |
| 195 base::Closure send_seek_request_ack_cb_; |
| 196 DemuxerReadyCB send_demuxer_ready_cb_; |
| 197 #endif |
| 161 | 198 |
| 162 WebMediaPlayerProxyAndroid* proxy_; | 199 WebMediaPlayerProxyAndroid* proxy_; |
| 163 int player_id_; | 200 int player_id_; |
| 164 | 201 |
| 165 scoped_refptr<media::MediaLog> media_log_; | 202 scoped_refptr<media::MediaLog> media_log_; |
| 166 UpdateNetworkStateCB update_network_state_cb_; | 203 UpdateNetworkStateCB update_network_state_cb_; |
| 167 DurationChangeCB duration_change_cb_; | 204 DurationChangeCB duration_change_cb_; |
| 168 | 205 |
| 169 scoped_ptr<media::ChunkDemuxer> chunk_demuxer_; | 206 scoped_ptr<media::ChunkDemuxer> chunk_demuxer_; |
| 170 scoped_ptr<WebKit::WebMediaSource> media_source_; | 207 scoped_ptr<WebKit::WebMediaSource> media_source_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 187 media::NeedKeyCB need_key_cb_; | 224 media::NeedKeyCB need_key_cb_; |
| 188 | 225 |
| 189 // The currently selected key system. Empty string means that no key system | 226 // The currently selected key system. Empty string means that no key system |
| 190 // has been selected. | 227 // has been selected. |
| 191 WebKit::WebString current_key_system_; | 228 WebKit::WebString current_key_system_; |
| 192 | 229 |
| 193 // Temporary for EME v0.1. In the future the init data type should be passed | 230 // Temporary for EME v0.1. In the future the init data type should be passed |
| 194 // through GenerateKeyRequest() directly from WebKit. | 231 // through GenerateKeyRequest() directly from WebKit. |
| 195 std::string init_data_type_; | 232 std::string init_data_type_; |
| 196 | 233 |
| 197 media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params audio_params_; | 234 // Lock used to serialize access for |seeking_|. |
| 198 media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params video_params_; | 235 mutable base::Lock seeking_lock_; |
| 236 bool seeking_; |
| 199 | 237 |
| 200 bool seeking_; | |
| 201 base::TimeDelta last_seek_time_; | 238 base::TimeDelta last_seek_time_; |
| 202 unsigned last_seek_request_id_; | 239 unsigned last_seek_request_id_; |
| 203 | 240 |
| 204 bool key_added_; | 241 bool key_added_; |
| 205 std::string key_system_; | 242 std::string key_system_; |
| 206 | 243 |
| 207 size_t access_unit_size_; | 244 size_t access_unit_size_; |
| 208 | 245 |
| 209 DISALLOW_COPY_AND_ASSIGN(MediaSourceDelegate); | 246 DISALLOW_COPY_AND_ASSIGN(MediaSourceDelegate); |
| 210 }; | 247 }; |
| 211 | 248 |
| 212 } // namespace content | 249 } // namespace content |
| 213 | 250 |
| 214 #endif // CONTENT_RENDERER_MEDIA_ANDROID_MEDIA_SOURCE_DELEGATE_H_ | 251 #endif // CONTENT_RENDERER_MEDIA_ANDROID_MEDIA_SOURCE_DELEGATE_H_ |
| OLD | NEW |