Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / media / base / android / media_decoder_job.cc
blobd96785e2121de96e6162c280da8ee3f6ef6dbdbf
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.
5 #include "media/base/android/media_decoder_job.h"
7 #include "base/bind.h"
8 #include "base/callback_helpers.h"
9 #include "base/debug/trace_event.h"
10 #include "base/message_loop/message_loop_proxy.h"
11 #include "media/base/android/media_codec_bridge.h"
12 #include "media/base/android/media_drm_bridge.h"
13 #include "media/base/bind_to_current_loop.h"
14 #include "media/base/buffers.h"
16 namespace media {
18 // Timeout value for media codec operations. Because the first
19 // DequeInputBuffer() can take about 150 milliseconds, use 250 milliseconds
20 // here. See http://b/9357571.
21 static const int kMediaCodecTimeoutInMilliseconds = 250;
23 MediaDecoderJob::MediaDecoderJob(
24 const scoped_refptr<base::SingleThreadTaskRunner>& decoder_task_runner,
25 const base::Closure& request_data_cb,
26 const base::Closure& config_changed_cb)
27 : need_to_reconfig_decoder_job_(false),
28 ui_task_runner_(base::MessageLoopProxy::current()),
29 decoder_task_runner_(decoder_task_runner),
30 needs_flush_(false),
31 input_eos_encountered_(false),
32 output_eos_encountered_(false),
33 skip_eos_enqueue_(true),
34 prerolling_(true),
35 request_data_cb_(request_data_cb),
36 config_changed_cb_(config_changed_cb),
37 current_demuxer_data_index_(0),
38 input_buf_index_(-1),
39 is_content_encrypted_(false),
40 stop_decode_pending_(false),
41 destroy_pending_(false),
42 is_requesting_demuxer_data_(false),
43 is_incoming_data_invalid_(false),
44 release_resources_pending_(false),
45 drm_bridge_(NULL),
46 drain_decoder_(false) {
47 InitializeReceivedData();
48 eos_unit_.end_of_stream = true;
51 MediaDecoderJob::~MediaDecoderJob() {
52 ReleaseMediaCodecBridge();
55 void MediaDecoderJob::OnDataReceived(const DemuxerData& data) {
56 DVLOG(1) << __FUNCTION__ << ": " << data.access_units.size() << " units";
57 DCHECK(ui_task_runner_->BelongsToCurrentThread());
58 DCHECK(NoAccessUnitsRemainingInChunk(false));
60 TRACE_EVENT_ASYNC_END2(
61 "media", "MediaDecoderJob::RequestData", this,
62 "Data type", data.type == media::DemuxerStream::AUDIO ? "AUDIO" : "VIDEO",
63 "Units read", data.access_units.size());
65 if (is_incoming_data_invalid_) {
66 is_incoming_data_invalid_ = false;
68 // If there is a pending callback, need to request the data again to get
69 // valid data.
70 if (!data_received_cb_.is_null())
71 request_data_cb_.Run();
72 else
73 is_requesting_demuxer_data_ = false;
74 return;
77 size_t next_demuxer_data_index = inactive_demuxer_data_index();
78 received_data_[next_demuxer_data_index] = data;
79 access_unit_index_[next_demuxer_data_index] = 0;
80 is_requesting_demuxer_data_ = false;
82 base::Closure done_cb = base::ResetAndReturn(&data_received_cb_);
84 // If this data request is for the inactive chunk, or |data_received_cb_|
85 // was set to null by Flush() or Release(), do nothing.
86 if (done_cb.is_null())
87 return;
89 if (stop_decode_pending_) {
90 DCHECK(is_decoding());
91 OnDecodeCompleted(MEDIA_CODEC_ABORT, kNoTimestamp(), kNoTimestamp());
92 return;
95 done_cb.Run();
98 void MediaDecoderJob::Prefetch(const base::Closure& prefetch_cb) {
99 DCHECK(ui_task_runner_->BelongsToCurrentThread());
100 DCHECK(data_received_cb_.is_null());
101 DCHECK(decode_cb_.is_null());
103 if (HasData()) {
104 DVLOG(1) << __FUNCTION__ << " : using previously received data";
105 ui_task_runner_->PostTask(FROM_HERE, prefetch_cb);
106 return;
109 DVLOG(1) << __FUNCTION__ << " : requesting data";
110 RequestData(prefetch_cb);
113 bool MediaDecoderJob::Decode(
114 base::TimeTicks start_time_ticks,
115 base::TimeDelta start_presentation_timestamp,
116 const DecoderCallback& callback) {
117 DCHECK(decode_cb_.is_null());
118 DCHECK(data_received_cb_.is_null());
119 DCHECK(ui_task_runner_->BelongsToCurrentThread());
120 if (!media_codec_bridge_ || need_to_reconfig_decoder_job_) {
121 if (drain_decoder_)
122 OnDecoderDrained();
123 need_to_reconfig_decoder_job_ = !CreateMediaCodecBridge();
124 skip_eos_enqueue_ = true;
125 if (need_to_reconfig_decoder_job_)
126 return false;
129 decode_cb_ = callback;
131 if (!HasData()) {
132 RequestData(base::Bind(&MediaDecoderJob::DecodeCurrentAccessUnit,
133 base::Unretained(this),
134 start_time_ticks,
135 start_presentation_timestamp));
136 return true;
139 DecodeCurrentAccessUnit(start_time_ticks, start_presentation_timestamp);
140 return true;
143 void MediaDecoderJob::StopDecode() {
144 DCHECK(ui_task_runner_->BelongsToCurrentThread());
145 DCHECK(is_decoding());
146 stop_decode_pending_ = true;
149 bool MediaDecoderJob::OutputEOSReached() const {
150 return !drain_decoder_ && output_eos_encountered_;
153 void MediaDecoderJob::SetDrmBridge(MediaDrmBridge* drm_bridge) {
154 drm_bridge_ = drm_bridge;
155 need_to_reconfig_decoder_job_ = true;
158 void MediaDecoderJob::Flush() {
159 DVLOG(1) << __FUNCTION__;
160 DCHECK(ui_task_runner_->BelongsToCurrentThread());
161 DCHECK(data_received_cb_.is_null());
162 DCHECK(decode_cb_.is_null());
164 // Clean up the received data.
165 current_demuxer_data_index_ = 0;
166 InitializeReceivedData();
167 if (is_requesting_demuxer_data_)
168 is_incoming_data_invalid_ = true;
169 input_eos_encountered_ = false;
170 output_eos_encountered_ = false;
171 drain_decoder_ = false;
173 // Do nothing, flush when the next Decode() happens.
174 needs_flush_ = true;
177 void MediaDecoderJob::BeginPrerolling(base::TimeDelta preroll_timestamp) {
178 DVLOG(1) << __FUNCTION__ << "(" << preroll_timestamp.InSecondsF() << ")";
179 DCHECK(ui_task_runner_->BelongsToCurrentThread());
180 DCHECK(!is_decoding());
182 preroll_timestamp_ = preroll_timestamp;
183 prerolling_ = true;
186 void MediaDecoderJob::ReleaseDecoderResources() {
187 DVLOG(1) << __FUNCTION__;
188 DCHECK(ui_task_runner_->BelongsToCurrentThread());
189 if (decode_cb_.is_null()) {
190 DCHECK(!drain_decoder_);
191 // Since the decoder job is not decoding data, we can safely destroy
192 // |media_codec_bridge_|.
193 ReleaseMediaCodecBridge();
194 return;
197 // Release |media_codec_bridge_| once decoding is completed.
198 release_resources_pending_ = true;
201 base::android::ScopedJavaLocalRef<jobject> MediaDecoderJob::GetMediaCrypto() {
202 base::android::ScopedJavaLocalRef<jobject> media_crypto;
203 if (drm_bridge_)
204 media_crypto = drm_bridge_->GetMediaCrypto();
205 return media_crypto;
208 void MediaDecoderJob::Release() {
209 DCHECK(ui_task_runner_->BelongsToCurrentThread());
210 DVLOG(1) << __FUNCTION__;
212 // If the decoder job is still decoding, we cannot delete the job immediately.
213 destroy_pending_ = is_decoding();
215 request_data_cb_.Reset();
216 data_received_cb_.Reset();
217 decode_cb_.Reset();
219 if (destroy_pending_) {
220 DVLOG(1) << __FUNCTION__ << " : delete is pending decode completion";
221 return;
224 delete this;
227 MediaCodecStatus MediaDecoderJob::QueueInputBuffer(const AccessUnit& unit) {
228 DVLOG(1) << __FUNCTION__;
229 DCHECK(decoder_task_runner_->BelongsToCurrentThread());
230 TRACE_EVENT0("media", __FUNCTION__);
232 int input_buf_index = input_buf_index_;
233 input_buf_index_ = -1;
235 // TODO(xhwang): Hide DequeueInputBuffer() and the index in MediaCodecBridge.
236 if (input_buf_index == -1) {
237 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds(
238 kMediaCodecTimeoutInMilliseconds);
239 MediaCodecStatus status =
240 media_codec_bridge_->DequeueInputBuffer(timeout, &input_buf_index);
241 if (status != MEDIA_CODEC_OK) {
242 DVLOG(1) << "DequeueInputBuffer fails: " << status;
243 return status;
247 // TODO(qinmin): skip frames if video is falling far behind.
248 DCHECK_GE(input_buf_index, 0);
249 if (unit.end_of_stream || unit.data.empty()) {
250 media_codec_bridge_->QueueEOS(input_buf_index);
251 return MEDIA_CODEC_INPUT_END_OF_STREAM;
254 if (unit.key_id.empty() || unit.iv.empty()) {
255 DCHECK(unit.iv.empty() || !unit.key_id.empty());
256 return media_codec_bridge_->QueueInputBuffer(
257 input_buf_index, &unit.data[0], unit.data.size(), unit.timestamp);
260 MediaCodecStatus status = media_codec_bridge_->QueueSecureInputBuffer(
261 input_buf_index,
262 &unit.data[0], unit.data.size(),
263 reinterpret_cast<const uint8*>(&unit.key_id[0]), unit.key_id.size(),
264 reinterpret_cast<const uint8*>(&unit.iv[0]), unit.iv.size(),
265 unit.subsamples.empty() ? NULL : &unit.subsamples[0],
266 unit.subsamples.size(),
267 unit.timestamp);
269 // In case of MEDIA_CODEC_NO_KEY, we must reuse the |input_buf_index_|.
270 // Otherwise MediaDrm will report errors.
271 if (status == MEDIA_CODEC_NO_KEY)
272 input_buf_index_ = input_buf_index;
274 return status;
277 bool MediaDecoderJob::HasData() const {
278 DCHECK(ui_task_runner_->BelongsToCurrentThread());
279 // When |input_eos_encountered_| is set, |access_unit_index_| and
280 // |current_demuxer_data_index_| must be pointing to an EOS unit,
281 // or a |kConfigChanged| unit if |drain_decoder_| is true. In both cases,
282 // we'll feed an EOS input unit to drain the decoder until we hit output EOS.
283 DCHECK(!input_eos_encountered_ || !NoAccessUnitsRemainingInChunk(true));
284 return !NoAccessUnitsRemainingInChunk(true) ||
285 !NoAccessUnitsRemainingInChunk(false);
288 void MediaDecoderJob::RequestData(const base::Closure& done_cb) {
289 DVLOG(1) << __FUNCTION__;
290 DCHECK(ui_task_runner_->BelongsToCurrentThread());
291 DCHECK(data_received_cb_.is_null());
292 DCHECK(!input_eos_encountered_);
293 DCHECK(NoAccessUnitsRemainingInChunk(false));
295 TRACE_EVENT_ASYNC_BEGIN0("media", "MediaDecoderJob::RequestData", this);
297 data_received_cb_ = done_cb;
299 // If we are already expecting new data, just set the callback and do
300 // nothing.
301 if (is_requesting_demuxer_data_)
302 return;
304 // The new incoming data will be stored as the next demuxer data chunk, since
305 // the decoder might still be decoding the current one.
306 size_t next_demuxer_data_index = inactive_demuxer_data_index();
307 received_data_[next_demuxer_data_index] = DemuxerData();
308 access_unit_index_[next_demuxer_data_index] = 0;
309 is_requesting_demuxer_data_ = true;
311 request_data_cb_.Run();
314 void MediaDecoderJob::DecodeCurrentAccessUnit(
315 base::TimeTicks start_time_ticks,
316 base::TimeDelta start_presentation_timestamp) {
317 DCHECK(ui_task_runner_->BelongsToCurrentThread());
318 DCHECK(!decode_cb_.is_null());
320 RequestCurrentChunkIfEmpty();
321 const AccessUnit& access_unit = CurrentAccessUnit();
322 if (CurrentAccessUnit().status == DemuxerStream::kConfigChanged) {
323 int index = CurrentReceivedDataChunkIndex();
324 const DemuxerConfigs& configs = received_data_[index].demuxer_configs[0];
325 bool reconfigure_needed = IsCodecReconfigureNeeded(configs);
326 SetDemuxerConfigs(configs);
327 if (!drain_decoder_) {
328 // If we haven't decoded any data yet, just skip the current access unit
329 // and request the MediaCodec to be recreated on next Decode().
330 if (skip_eos_enqueue_ || !reconfigure_needed) {
331 need_to_reconfig_decoder_job_ =
332 need_to_reconfig_decoder_job_ || reconfigure_needed;
333 // Report MEDIA_CODEC_OK status so decoder will continue decoding and
334 // MEDIA_CODEC_OUTPUT_FORMAT_CHANGED status will come later.
335 ui_task_runner_->PostTask(FROM_HERE, base::Bind(
336 &MediaDecoderJob::OnDecodeCompleted, base::Unretained(this),
337 MEDIA_CODEC_OK, kNoTimestamp(), kNoTimestamp()));
338 return;
340 // Start draining the decoder so that all the remaining frames are
341 // rendered.
342 drain_decoder_ = true;
346 DCHECK(!(needs_flush_ && drain_decoder_));
347 decoder_task_runner_->PostTask(FROM_HERE, base::Bind(
348 &MediaDecoderJob::DecodeInternal, base::Unretained(this),
349 drain_decoder_ ? eos_unit_ : access_unit,
350 start_time_ticks, start_presentation_timestamp, needs_flush_,
351 media::BindToCurrentLoop(base::Bind(
352 &MediaDecoderJob::OnDecodeCompleted, base::Unretained(this)))));
353 needs_flush_ = false;
356 void MediaDecoderJob::DecodeInternal(
357 const AccessUnit& unit,
358 base::TimeTicks start_time_ticks,
359 base::TimeDelta start_presentation_timestamp,
360 bool needs_flush,
361 const MediaDecoderJob::DecoderCallback& callback) {
362 DVLOG(1) << __FUNCTION__;
363 DCHECK(decoder_task_runner_->BelongsToCurrentThread());
364 TRACE_EVENT0("media", __FUNCTION__);
366 if (needs_flush) {
367 DVLOG(1) << "DecodeInternal needs flush.";
368 input_eos_encountered_ = false;
369 output_eos_encountered_ = false;
370 MediaCodecStatus reset_status = media_codec_bridge_->Reset();
371 if (MEDIA_CODEC_OK != reset_status) {
372 callback.Run(reset_status, kNoTimestamp(), kNoTimestamp());
373 return;
377 // Once output EOS has occurred, we should not be asked to decode again.
378 // MediaCodec has undefined behavior if similarly asked to decode after output
379 // EOS.
380 DCHECK(!output_eos_encountered_);
382 // For aborted access unit, just skip it and inform the player.
383 if (unit.status == DemuxerStream::kAborted) {
384 callback.Run(MEDIA_CODEC_ABORT, kNoTimestamp(), kNoTimestamp());
385 return;
388 if (skip_eos_enqueue_) {
389 if (unit.end_of_stream || unit.data.empty()) {
390 input_eos_encountered_ = true;
391 output_eos_encountered_ = true;
392 callback.Run(MEDIA_CODEC_OUTPUT_END_OF_STREAM, kNoTimestamp(),
393 kNoTimestamp());
394 return;
397 skip_eos_enqueue_ = false;
400 MediaCodecStatus input_status = MEDIA_CODEC_INPUT_END_OF_STREAM;
401 if (!input_eos_encountered_) {
402 input_status = QueueInputBuffer(unit);
403 if (input_status == MEDIA_CODEC_INPUT_END_OF_STREAM) {
404 input_eos_encountered_ = true;
405 } else if (input_status != MEDIA_CODEC_OK) {
406 callback.Run(input_status, kNoTimestamp(), kNoTimestamp());
407 return;
411 int buffer_index = 0;
412 size_t offset = 0;
413 size_t size = 0;
414 base::TimeDelta presentation_timestamp;
416 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds(
417 kMediaCodecTimeoutInMilliseconds);
419 MediaCodecStatus status = MEDIA_CODEC_OK;
420 bool has_format_change = false;
421 // Dequeue the output buffer until a MEDIA_CODEC_OK, MEDIA_CODEC_ERROR or
422 // MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER is received.
423 do {
424 status = media_codec_bridge_->DequeueOutputBuffer(
425 timeout,
426 &buffer_index,
427 &offset,
428 &size,
429 &presentation_timestamp,
430 &output_eos_encountered_,
431 NULL);
432 if (status == MEDIA_CODEC_OUTPUT_FORMAT_CHANGED) {
433 // TODO(qinmin): instead of waiting for the next output buffer to be
434 // dequeued, post a task on the UI thread to signal the format change.
435 has_format_change = true;
437 } while (status != MEDIA_CODEC_OK && status != MEDIA_CODEC_ERROR &&
438 status != MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER);
440 if (status != MEDIA_CODEC_OK) {
441 callback.Run(status, kNoTimestamp(), kNoTimestamp());
442 return;
445 // TODO(xhwang/qinmin): This logic is correct but strange. Clean it up.
446 if (output_eos_encountered_)
447 status = MEDIA_CODEC_OUTPUT_END_OF_STREAM;
448 else if (has_format_change)
449 status = MEDIA_CODEC_OUTPUT_FORMAT_CHANGED;
451 bool render_output = presentation_timestamp >= preroll_timestamp_ &&
452 (status != MEDIA_CODEC_OUTPUT_END_OF_STREAM || size != 0u);
453 base::TimeDelta time_to_render;
454 DCHECK(!start_time_ticks.is_null());
455 if (render_output && ComputeTimeToRender()) {
456 time_to_render = presentation_timestamp - (base::TimeTicks::Now() -
457 start_time_ticks + start_presentation_timestamp);
460 if (time_to_render > base::TimeDelta()) {
461 decoder_task_runner_->PostDelayedTask(
462 FROM_HERE,
463 base::Bind(&MediaDecoderJob::ReleaseOutputBuffer,
464 base::Unretained(this),
465 buffer_index,
466 size,
467 render_output,
468 presentation_timestamp,
469 base::Bind(callback, status)),
470 time_to_render);
471 return;
474 // TODO(qinmin): The codec is lagging behind, need to recalculate the
475 // |start_presentation_timestamp_| and |start_time_ticks_| in
476 // media_source_player.cc.
477 DVLOG(1) << "codec is lagging behind :" << time_to_render.InMicroseconds();
478 if (render_output) {
479 // The player won't expect a timestamp smaller than the
480 // |start_presentation_timestamp|. However, this could happen due to decoder
481 // errors.
482 presentation_timestamp = std::max(
483 presentation_timestamp, start_presentation_timestamp);
484 } else {
485 presentation_timestamp = kNoTimestamp();
487 ReleaseOutputCompletionCallback completion_callback = base::Bind(
488 callback, status);
489 ReleaseOutputBuffer(buffer_index, size, render_output, presentation_timestamp,
490 completion_callback);
493 void MediaDecoderJob::OnDecodeCompleted(
494 MediaCodecStatus status, base::TimeDelta current_presentation_timestamp,
495 base::TimeDelta max_presentation_timestamp) {
496 DCHECK(ui_task_runner_->BelongsToCurrentThread());
498 if (destroy_pending_) {
499 DVLOG(1) << __FUNCTION__ << " : completing pending deletion";
500 delete this;
501 return;
504 if (status == MEDIA_CODEC_OUTPUT_END_OF_STREAM)
505 output_eos_encountered_ = true;
507 DCHECK(!decode_cb_.is_null());
509 // If output was queued for rendering, then we have completed prerolling.
510 if (current_presentation_timestamp != kNoTimestamp() ||
511 status == MEDIA_CODEC_OUTPUT_END_OF_STREAM) {
512 prerolling_ = false;
515 switch (status) {
516 case MEDIA_CODEC_OK:
517 case MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER:
518 case MEDIA_CODEC_OUTPUT_FORMAT_CHANGED:
519 case MEDIA_CODEC_OUTPUT_END_OF_STREAM:
520 if (!input_eos_encountered_) {
521 CurrentDataConsumed(
522 CurrentAccessUnit().status == DemuxerStream::kConfigChanged);
523 access_unit_index_[current_demuxer_data_index_]++;
525 break;
527 case MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER:
528 case MEDIA_CODEC_INPUT_END_OF_STREAM:
529 case MEDIA_CODEC_NO_KEY:
530 case MEDIA_CODEC_ABORT:
531 case MEDIA_CODEC_ERROR:
532 // Do nothing.
533 break;
535 case MEDIA_CODEC_OUTPUT_BUFFERS_CHANGED:
536 DCHECK(false) << "Invalid output status";
537 break;
540 if (status == MEDIA_CODEC_OUTPUT_END_OF_STREAM && drain_decoder_) {
541 OnDecoderDrained();
542 status = MEDIA_CODEC_OK;
545 if (status == MEDIA_CODEC_OUTPUT_FORMAT_CHANGED) {
546 if (UpdateOutputFormat())
547 config_changed_cb_.Run();
548 status = MEDIA_CODEC_OK;
551 if (release_resources_pending_) {
552 ReleaseMediaCodecBridge();
553 release_resources_pending_ = false;
554 if (drain_decoder_)
555 OnDecoderDrained();
558 stop_decode_pending_ = false;
559 base::ResetAndReturn(&decode_cb_).Run(
560 status, current_presentation_timestamp, max_presentation_timestamp);
563 const AccessUnit& MediaDecoderJob::CurrentAccessUnit() const {
564 DCHECK(ui_task_runner_->BelongsToCurrentThread());
565 DCHECK(HasData());
566 size_t index = CurrentReceivedDataChunkIndex();
567 return received_data_[index].access_units[access_unit_index_[index]];
570 size_t MediaDecoderJob::CurrentReceivedDataChunkIndex() const {
571 return NoAccessUnitsRemainingInChunk(true) ?
572 inactive_demuxer_data_index() : current_demuxer_data_index_;
575 bool MediaDecoderJob::NoAccessUnitsRemainingInChunk(
576 bool is_active_chunk) const {
577 DCHECK(ui_task_runner_->BelongsToCurrentThread());
578 size_t index = is_active_chunk ? current_demuxer_data_index_ :
579 inactive_demuxer_data_index();
580 return received_data_[index].access_units.size() <= access_unit_index_[index];
583 void MediaDecoderJob::RequestCurrentChunkIfEmpty() {
584 DCHECK(ui_task_runner_->BelongsToCurrentThread());
585 DCHECK(HasData());
586 if (!NoAccessUnitsRemainingInChunk(true))
587 return;
589 // Requests new data if the the last access unit of the next chunk is not EOS.
590 current_demuxer_data_index_ = inactive_demuxer_data_index();
591 const AccessUnit last_access_unit =
592 received_data_[current_demuxer_data_index_].access_units.back();
593 if (!last_access_unit.end_of_stream &&
594 last_access_unit.status != DemuxerStream::kAborted) {
595 RequestData(base::Closure());
599 void MediaDecoderJob::InitializeReceivedData() {
600 for (size_t i = 0; i < 2; ++i) {
601 received_data_[i] = DemuxerData();
602 access_unit_index_[i] = 0;
606 void MediaDecoderJob::OnDecoderDrained() {
607 DVLOG(1) << __FUNCTION__;
608 DCHECK(ui_task_runner_->BelongsToCurrentThread());
609 DCHECK(drain_decoder_);
611 input_eos_encountered_ = false;
612 output_eos_encountered_ = false;
613 drain_decoder_ = false;
614 ReleaseMediaCodecBridge();
615 // Increase the access unit index so that the new decoder will not handle
616 // the config change again.
617 access_unit_index_[current_demuxer_data_index_]++;
618 CurrentDataConsumed(true);
621 bool MediaDecoderJob::CreateMediaCodecBridge() {
622 DVLOG(1) << __FUNCTION__;
623 DCHECK(ui_task_runner_->BelongsToCurrentThread());
624 DCHECK(decode_cb_.is_null());
626 if (!HasStream()) {
627 ReleaseMediaCodecBridge();
628 return false;
631 // Create |media_codec_bridge_| only if config changes.
632 if (media_codec_bridge_ && !need_to_reconfig_decoder_job_)
633 return true;
635 base::android::ScopedJavaLocalRef<jobject> media_crypto = GetMediaCrypto();
636 if (is_content_encrypted_ && media_crypto.is_null())
637 return false;
639 ReleaseMediaCodecBridge();
640 DVLOG(1) << __FUNCTION__ << " : creating new media codec bridge";
642 return CreateMediaCodecBridgeInternal();
645 bool MediaDecoderJob::IsCodecReconfigureNeeded(
646 const DemuxerConfigs& configs) const {
647 if (!AreDemuxerConfigsChanged(configs))
648 return false;
649 return true;
652 bool MediaDecoderJob::UpdateOutputFormat() {
653 return false;
656 void MediaDecoderJob::ReleaseMediaCodecBridge() {
657 if (!media_codec_bridge_)
658 return;
660 media_codec_bridge_.reset();
661 input_buf_index_ = -1;
664 } // namespace media