Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Side by Side Diff: media/base/android/media_decoder_job.h

Issue 898843002: Use cached Key frames to avoid browser seek (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/android/audio_decoder_job.cc ('k') | media/base/android/media_decoder_job.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 MEDIA_BASE_ANDROID_MEDIA_DECODER_JOB_H_ 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_DECODER_JOB_H_
6 #define MEDIA_BASE_ANDROID_MEDIA_DECODER_JOB_H_ 6 #define MEDIA_BASE_ANDROID_MEDIA_DECODER_JOB_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "media/base/android/demuxer_stream_player_params.h" 11 #include "media/base/android/demuxer_stream_player_params.h"
12 #include "media/base/android/media_codec_bridge.h" 12 #include "media/base/android/media_codec_bridge.h"
13 #include "ui/gl/android/scoped_java_surface.h" 13 #include "ui/gl/android/scoped_java_surface.h"
14 14
15 namespace base { 15 namespace base {
16 class SingleThreadTaskRunner; 16 class SingleThreadTaskRunner;
17 } 17 }
18 18
19 namespace media { 19 namespace media {
20 20
21 class MediaDrmBridge; 21 class MediaDrmBridge;
22 22
23 // Class for managing all the decoding tasks. Each decoding task will be posted 23 // Class for managing all the decoding tasks. Each decoding task will be posted
24 // onto the same thread. The thread will be stopped once Stop() is called. 24 // onto the same thread. The thread will be stopped once Stop() is called.
25 // Data is stored in 2 chunks. When new data arrives, it is always stored in 25 // Data is stored in 2 chunks. When new data arrives, it is always stored in
26 // an inactive chunk. And when the current active chunk becomes empty, a new 26 // an inactive chunk. And when the current active chunk becomes empty, a new
27 // data request will be sent to the renderer. 27 // data request will be sent to the renderer.
28 class MediaDecoderJob { 28 class MediaDecoderJob {
29 public: 29 public:
30 // Return value when Decode() is called.
31 enum MediaDecoderJobStatus {
32 STATUS_SUCCESS,
33 STATUS_KEY_FRAME_REQUIRED,
34 STATUS_FAILURE,
35 };
36
30 struct Deleter { 37 struct Deleter {
31 inline void operator()(MediaDecoderJob* ptr) const { ptr->Release(); } 38 inline void operator()(MediaDecoderJob* ptr) const { ptr->Release(); }
32 }; 39 };
33 40
34 // Callback when a decoder job finishes its work. Args: whether decode 41 // Callback when a decoder job finishes its work. Args: whether decode
35 // finished successfully, current presentation time, max presentation time. 42 // finished successfully, current presentation time, max presentation time.
36 // If the current presentation time is equal to kNoTimestamp(), the decoder 43 // If the current presentation time is equal to kNoTimestamp(), the decoder
37 // job skipped rendering of the decoded output and the callback target should 44 // job skipped rendering of the decoded output and the callback target should
38 // ignore the timestamps provided. 45 // ignore the timestamps provided.
39 typedef base::Callback<void(MediaCodecStatus, base::TimeDelta, 46 typedef base::Callback<void(MediaCodecStatus, base::TimeDelta,
(...skipping 10 matching lines...) Expand all
50 // Called by MediaSourcePlayer when more data for this object has arrived. 57 // Called by MediaSourcePlayer when more data for this object has arrived.
51 void OnDataReceived(const DemuxerData& data); 58 void OnDataReceived(const DemuxerData& data);
52 59
53 // Prefetch so we know the decoder job has data when we call Decode(). 60 // Prefetch so we know the decoder job has data when we call Decode().
54 // |prefetch_cb| - Run when prefetching has completed. 61 // |prefetch_cb| - Run when prefetching has completed.
55 void Prefetch(const base::Closure& prefetch_cb); 62 void Prefetch(const base::Closure& prefetch_cb);
56 63
57 // Called by MediaSourcePlayer to decode some data. 64 // Called by MediaSourcePlayer to decode some data.
58 // |callback| - Run when decode operation has completed. 65 // |callback| - Run when decode operation has completed.
59 // 66 //
60 // Returns true if the next decode was started and |callback| will be 67 // Returns STATUS_SUCCESS on success, or STATUS_FAILURE on failure, or
61 // called when the decode operation is complete. 68 // STATUS_KEY_FRAME_REQUIRED if a browser seek is required. |callback| is
62 // Returns false if |media_codec_bridge_| cannot be created; |callback| is 69 // ignored and will not be called for the latter 2 cases.
63 // ignored and will not be called. 70 MediaDecoderJobStatus Decode(base::TimeTicks start_time_ticks,
64 bool Decode(base::TimeTicks start_time_ticks, 71 base::TimeDelta start_presentation_timestamp,
65 base::TimeDelta start_presentation_timestamp, 72 const DecoderCallback& callback);
66 const DecoderCallback& callback);
67 73
68 // Called to stop the last Decode() early. 74 // Called to stop the last Decode() early.
69 // If the decoder is in the process of decoding the next frame, then 75 // If the decoder is in the process of decoding the next frame, then
70 // this method will just allow the decode to complete as normal. If 76 // this method will just allow the decode to complete as normal. If
71 // this object is waiting for a data request to complete, then this method 77 // this object is waiting for a data request to complete, then this method
72 // will wait for the data to arrive and then call the |callback| 78 // will wait for the data to arrive and then call the |callback|
73 // passed to Decode() with a status of MEDIA_CODEC_ABORT. This ensures that 79 // passed to Decode() with a status of MEDIA_CODEC_ABORT. This ensures that
74 // the |callback| passed to Decode() is always called and the status 80 // the |callback| passed to Decode() is always called and the status
75 // reflects whether data was actually decoded or the decode terminated early. 81 // reflects whether data was actually decoded or the decode terminated early.
76 void StopDecode(); 82 void StopDecode();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // Returns true if the "time to render" needs to be computed for frames in 131 // Returns true if the "time to render" needs to be computed for frames in
126 // this decoder job. 132 // this decoder job.
127 virtual bool ComputeTimeToRender() const = 0; 133 virtual bool ComputeTimeToRender() const = 0;
128 134
129 // Gets MediaCrypto object from |drm_bridge_|. 135 // Gets MediaCrypto object from |drm_bridge_|.
130 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto(); 136 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto();
131 137
132 // Releases the |media_codec_bridge_|. 138 // Releases the |media_codec_bridge_|.
133 void ReleaseMediaCodecBridge(); 139 void ReleaseMediaCodecBridge();
134 140
141 // Sets the current frame to a previously cached key frame. Returns true if
142 // a key frame is found, or false otherwise.
143 // TODO(qinmin): add UMA to study the cache hit ratio for key frames.
144 bool SetCurrentFrameToPreviouslyCachedKeyFrame();
145
135 MediaDrmBridge* drm_bridge() { return drm_bridge_; } 146 MediaDrmBridge* drm_bridge() { return drm_bridge_; }
136 147
137 void set_is_content_encrypted(bool is_content_encrypted) { 148 void set_is_content_encrypted(bool is_content_encrypted) {
138 is_content_encrypted_ = is_content_encrypted; 149 is_content_encrypted_ = is_content_encrypted;
139 } 150 }
140 151
141 bool need_to_reconfig_decoder_job_; 152 bool need_to_reconfig_decoder_job_;
142 153
143 scoped_ptr<MediaCodecBridge> media_codec_bridge_; 154 scoped_ptr<MediaCodecBridge> media_codec_bridge_;
144 155
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 213
203 // Requests new data for the current chunk if it runs out of data. 214 // Requests new data for the current chunk if it runs out of data.
204 void RequestCurrentChunkIfEmpty(); 215 void RequestCurrentChunkIfEmpty();
205 216
206 // Initializes |received_data_| and |access_unit_index_|. 217 // Initializes |received_data_| and |access_unit_index_|.
207 void InitializeReceivedData(); 218 void InitializeReceivedData();
208 219
209 // Called when the decoder is completely drained and is ready to be released. 220 // Called when the decoder is completely drained and is ready to be released.
210 void OnDecoderDrained(); 221 void OnDecoderDrained();
211 222
212 // Creates |media_codec_bridge_| for decoding purpose. Returns true if it is 223 // Creates |media_codec_bridge_| for decoding purpose.
213 // created, or false otherwise. 224 // Returns STATUS_SUCCESS on success, or STATUS_FAILURE on failure, or
214 bool CreateMediaCodecBridge(); 225 // STATUS_KEY_FRAME_REQUIRED if a browser seek is required.
215 226 MediaDecoderJobStatus CreateMediaCodecBridge();
216 // Called when an access unit is consumed by the decoder. |is_config_change|
217 // indicates whether the current access unit is a config change. If it is
218 // true, the next access unit is guarateed to be an I-frame.
219 virtual void CurrentDataConsumed(bool is_config_change) {}
220 227
221 // Implemented by the child class to create |media_codec_bridge_| for a 228 // Implemented by the child class to create |media_codec_bridge_| for a
222 // particular stream. Returns true if it is created, or false otherwise. 229 // particular stream.
223 virtual bool CreateMediaCodecBridgeInternal() = 0; 230 // Returns STATUS_SUCCESS on success, or STATUS_FAILURE on failure, or
231 // STATUS_KEY_FRAME_REQUIRED if a browser seek is required.
232 virtual MediaDecoderJobStatus CreateMediaCodecBridgeInternal() = 0;
224 233
225 // Returns true if the |configs| doesn't match the current demuxer configs 234 // Returns true if the |configs| doesn't match the current demuxer configs
226 // the decoder job has. 235 // the decoder job has.
227 virtual bool AreDemuxerConfigsChanged( 236 virtual bool AreDemuxerConfigsChanged(
228 const DemuxerConfigs& configs) const = 0; 237 const DemuxerConfigs& configs) const = 0;
229 238
230 // Returns true if |media_codec_bridge_| needs to be reconfigured for the 239 // Returns true if |media_codec_bridge_| needs to be reconfigured for the
231 // new DemuxerConfigs, or false otherwise. 240 // new DemuxerConfigs, or false otherwise.
232 virtual bool IsCodecReconfigureNeeded(const DemuxerConfigs& configs) const; 241 virtual bool IsCodecReconfigureNeeded(const DemuxerConfigs& configs) const;
233 242
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 // This access unit is passed to the decoder during config changes to drain 352 // This access unit is passed to the decoder during config changes to drain
344 // the decoder. 353 // the decoder.
345 AccessUnit eos_unit_; 354 AccessUnit eos_unit_;
346 355
347 DISALLOW_IMPLICIT_CONSTRUCTORS(MediaDecoderJob); 356 DISALLOW_IMPLICIT_CONSTRUCTORS(MediaDecoderJob);
348 }; 357 };
349 358
350 } // namespace media 359 } // namespace media
351 360
352 #endif // MEDIA_BASE_ANDROID_MEDIA_DECODER_JOB_H_ 361 #endif // MEDIA_BASE_ANDROID_MEDIA_DECODER_JOB_H_
OLDNEW
« no previous file with comments | « media/base/android/audio_decoder_job.cc ('k') | media/base/android/media_decoder_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698