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