OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef WEBKIT_RENDERER_MEDIA_ANDROID_MEDIA_SOURCE_DELEGATE_H_ | |
6 #define WEBKIT_RENDERER_MEDIA_ANDROID_MEDIA_SOURCE_DELEGATE_H_ | |
7 | |
8 #include "base/callback.h" | |
9 #include "base/memory/ref_counted.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "base/time.h" | |
13 #include "media/base/decryptor.h" | |
14 #include "media/base/demuxer.h" | |
15 #include "media/base/media_keys.h" | |
16 #include "media/base/pipeline_status.h" | |
17 #include "media/base/ranges.h" | |
18 #include "media/base/text_track.h" | |
19 #include "third_party/WebKit/public/web/WebMediaPlayer.h" | |
20 | |
21 namespace media { | |
22 class ChunkDemuxer; | |
23 class DecoderBuffer; | |
24 class DemuxerStream; | |
25 class MediaLog; | |
26 struct MediaPlayerHostMsg_ReadFromDemuxerAck_Params; | |
27 } | |
28 | |
29 namespace webkit_media { | |
30 | |
31 class ProxyDecryptor; | |
32 class WebMediaPlayerProxyAndroid; | |
33 | |
34 class MediaSourceDelegate : public media::DemuxerHost { | |
35 public: | |
36 typedef base::Callback<void(WebKit::WebMediaPlayer::NetworkState)> | |
37 UpdateNetworkStateCB; | |
38 typedef base::Callback<void(const base::TimeDelta&)> DurationChangeCB; | |
39 | |
40 // Helper class used by scoped_ptr to destroy an instance of | |
41 // MediaSourceDelegate. | |
42 class Destroyer { | |
43 public: | |
44 inline void operator()(void* media_source_delegate) const { | |
45 static_cast<MediaSourceDelegate*>(media_source_delegate)->Destroy(); | |
46 } | |
47 }; | |
48 | |
49 MediaSourceDelegate(WebMediaPlayerProxyAndroid* proxy, | |
50 int player_id, | |
51 media::MediaLog* media_log); | |
52 // Initialize the MediaSourceDelegate. |media_source| will be owned by | |
53 // this object after this call. | |
54 void InitializeMediaSource( | |
55 WebKit::WebMediaSource* media_source, | |
56 const media::NeedKeyCB& need_key_cb, | |
57 const UpdateNetworkStateCB& update_network_state_cb, | |
58 const DurationChangeCB& duration_change_cb); | |
59 #if defined(GOOGLE_TV) | |
60 void InitializeMediaStream( | |
61 media::Demuxer* demuxer, | |
62 const UpdateNetworkStateCB& update_network_state_cb); | |
63 #endif | |
64 | |
65 const WebKit::WebTimeRanges& Buffered(); | |
66 size_t DecodedFrameCount() const; | |
67 size_t DroppedFrameCount() const; | |
68 size_t AudioDecodedByteCount() const; | |
69 size_t VideoDecodedByteCount() const; | |
70 | |
71 void Seek(base::TimeDelta time); | |
72 | |
73 void CancelPendingSeek(); | |
74 | |
75 void NotifyDemuxerReady(const std::string& key_system); | |
76 | |
77 // Called when DemuxerStreamPlayer needs to read data from ChunkDemuxer. | |
78 // If it's the first request after the seek, |seek_done| will be true. | |
79 void OnReadFromDemuxer(media::DemuxerStream::Type type, bool seek_done); | |
80 | |
81 // Called when the player needs the new config data from ChunkDemuxer. | |
82 void OnMediaConfigRequest(); | |
83 | |
84 // Called by the Destroyer to destroy an instance of this object. | |
85 void Destroy(); | |
86 | |
87 private: | |
88 // This is private to enforce use of the Destroyer. | |
89 virtual ~MediaSourceDelegate(); | |
90 | |
91 // Methods inherited from DemuxerHost. | |
92 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; | |
93 virtual void AddBufferedByteRange(int64 start, int64 end) OVERRIDE; | |
94 virtual void AddBufferedTimeRange(base::TimeDelta start, | |
95 base::TimeDelta end) OVERRIDE; | |
96 virtual void SetDuration(base::TimeDelta duration) OVERRIDE; | |
97 virtual void OnDemuxerError(media::PipelineStatus status) OVERRIDE; | |
98 | |
99 // Callbacks for ChunkDemuxer. | |
100 void OnDemuxerInitDone(media::PipelineStatus status); | |
101 void OnDemuxerStopDone(); | |
102 void OnDemuxerOpened(); | |
103 void OnNeedKey(const std::string& type, | |
104 const std::string& session_id, | |
105 scoped_ptr<uint8[]> init_data, | |
106 int init_data_size); | |
107 scoped_ptr<media::TextTrack> OnAddTextTrack(media::TextKind kind, | |
108 const std::string& label, | |
109 const std::string& language); | |
110 | |
111 // Reads an access unit from the demuxer stream |stream| and stores it in | |
112 // the |index|th access unit in |params|. | |
113 void ReadFromDemuxerStream( | |
114 media::DemuxerStream* stream, | |
115 media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params* params, | |
116 size_t index); | |
117 void OnBufferReady( | |
118 media::DemuxerStream* stream, | |
119 media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params* params, | |
120 size_t index, | |
121 media::DemuxerStream::Status status, | |
122 const scoped_refptr<media::DecoderBuffer>& buffer); | |
123 | |
124 // Helper function for calculating duration. | |
125 int GetDurationMs(); | |
126 | |
127 base::WeakPtrFactory<MediaSourceDelegate> weak_this_; | |
128 | |
129 WebMediaPlayerProxyAndroid* proxy_; | |
130 int player_id_; | |
131 | |
132 scoped_refptr<media::MediaLog> media_log_; | |
133 UpdateNetworkStateCB update_network_state_cb_; | |
134 DurationChangeCB duration_change_cb_; | |
135 | |
136 scoped_ptr<media::ChunkDemuxer> chunk_demuxer_; | |
137 scoped_ptr<WebKit::WebMediaSource> media_source_; | |
138 media::Demuxer* demuxer_; | |
139 | |
140 media::PipelineStatistics statistics_; | |
141 media::Ranges<base::TimeDelta> buffered_time_ranges_; | |
142 // Keep a list of buffered time ranges. | |
143 WebKit::WebTimeRanges buffered_web_time_ranges_; | |
144 | |
145 media::NeedKeyCB need_key_cb_; | |
146 | |
147 // The currently selected key system. Empty string means that no key system | |
148 // has been selected. | |
149 WebKit::WebString current_key_system_; | |
150 | |
151 // Temporary for EME v0.1. In the future the init data type should be passed | |
152 // through GenerateKeyRequest() directly from WebKit. | |
153 std::string init_data_type_; | |
154 | |
155 scoped_ptr<media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params> audio_params_; | |
156 scoped_ptr<media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params> video_params_; | |
157 | |
158 bool seeking_; | |
159 size_t access_unit_size_; | |
160 | |
161 DISALLOW_COPY_AND_ASSIGN(MediaSourceDelegate); | |
162 }; | |
163 | |
164 } // namespace webkit_media | |
165 #endif // WEBKIT_RENDERER_MEDIA_ANDROID_MEDIA_SOURCE_DELEGATE_H_ | |
OLD | NEW |