Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / media / base / android / media_decoder_job.cc
index b7eef0c..c57da3a 100644 (file)
@@ -72,13 +72,19 @@ void MediaDecoderJob::OnDataReceived(const DemuxerData& data) {
   is_requesting_demuxer_data_ = false;
 
   base::Closure done_cb = base::ResetAndReturn(&on_data_received_cb_);
+
+  // If this data request is for the inactive chunk, or |on_data_received_cb_|
+  // was set to null by ClearData() or Release(), do nothing.
+  if (done_cb.is_null())
+    return;
+
   if (stop_decode_pending_) {
-    OnDecodeCompleted(MEDIA_CODEC_STOPPED, kNoTimestamp(), 0);
+    DCHECK(is_decoding());
+    OnDecodeCompleted(MEDIA_CODEC_STOPPED, kNoTimestamp(), kNoTimestamp());
     return;
   }
 
-  if (!done_cb.is_null())
-    done_cb.Run();
+  done_cb.Run();
 }
 
 void MediaDecoderJob::Prefetch(const base::Closure& prefetch_cb) {
@@ -269,8 +275,7 @@ void MediaDecoderJob::DecodeCurrentAccessUnit(
                               base::Bind(&MediaDecoderJob::OnDecodeCompleted,
                                          base::Unretained(this),
                                          MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER,
-                                         kNoTimestamp(),
-                                         0));
+                                         kNoTimestamp(), kNoTimestamp()));
     return;
   }
 
@@ -299,7 +304,7 @@ void MediaDecoderJob::DecodeInternal(
     output_eos_encountered_ = false;
     MediaCodecStatus reset_status = media_codec_bridge_->Reset();
     if (MEDIA_CODEC_OK != reset_status) {
-      callback.Run(reset_status, kNoTimestamp(), 0);
+      callback.Run(reset_status, kNoTimestamp(), kNoTimestamp());
       return;
     }
   }
@@ -312,7 +317,7 @@ void MediaDecoderJob::DecodeInternal(
   // For aborted access unit, just skip it and inform the player.
   if (unit.status == DemuxerStream::kAborted) {
     // TODO(qinmin): use a new enum instead of MEDIA_CODEC_STOPPED.
-    callback.Run(MEDIA_CODEC_STOPPED, kNoTimestamp(), 0);
+    callback.Run(MEDIA_CODEC_STOPPED, kNoTimestamp(), kNoTimestamp());
     return;
   }
 
@@ -320,7 +325,8 @@ void MediaDecoderJob::DecodeInternal(
     if (unit.end_of_stream || unit.data.empty()) {
       input_eos_encountered_ = true;
       output_eos_encountered_ = true;
-      callback.Run(MEDIA_CODEC_OUTPUT_END_OF_STREAM, kNoTimestamp(), 0);
+      callback.Run(MEDIA_CODEC_OUTPUT_END_OF_STREAM, kNoTimestamp(),
+                   kNoTimestamp());
       return;
     }
 
@@ -333,7 +339,7 @@ void MediaDecoderJob::DecodeInternal(
     if (input_status == MEDIA_CODEC_INPUT_END_OF_STREAM) {
       input_eos_encountered_ = true;
     } else if (input_status != MEDIA_CODEC_OK) {
-      callback.Run(input_status, kNoTimestamp(), 0);
+      callback.Run(input_status, kNoTimestamp(), kNoTimestamp());
       return;
     }
   }
@@ -360,7 +366,7 @@ void MediaDecoderJob::DecodeInternal(
         !media_codec_bridge_->GetOutputBuffers()) {
       status = MEDIA_CODEC_ERROR;
     }
-    callback.Run(status, kNoTimestamp(), 0);
+    callback.Run(status, kNoTimestamp(), kNoTimestamp());
     return;
   }
 
@@ -387,7 +393,8 @@ void MediaDecoderJob::DecodeInternal(
                    buffer_index,
                    size,
                    render_output,
-                   base::Bind(callback, status, presentation_timestamp)),
+                   presentation_timestamp,
+                   base::Bind(callback, status)),
         time_to_render);
     return;
   }
@@ -406,13 +413,14 @@ void MediaDecoderJob::DecodeInternal(
     presentation_timestamp = kNoTimestamp();
   }
   ReleaseOutputCompletionCallback completion_callback = base::Bind(
-      callback, status, presentation_timestamp);
-  ReleaseOutputBuffer(buffer_index, size, render_output, completion_callback);
+      callback, status);
+  ReleaseOutputBuffer(buffer_index, size, render_output, presentation_timestamp,
+                      completion_callback);
 }
 
 void MediaDecoderJob::OnDecodeCompleted(
-    MediaCodecStatus status, base::TimeDelta presentation_timestamp,
-    size_t audio_output_bytes) {
+    MediaCodecStatus status, base::TimeDelta current_presentation_timestamp,
+    base::TimeDelta max_presentation_timestamp) {
   DCHECK(ui_task_runner_->BelongsToCurrentThread());
 
   if (destroy_pending_) {
@@ -424,7 +432,7 @@ void MediaDecoderJob::OnDecodeCompleted(
   DCHECK(!decode_cb_.is_null());
 
   // If output was queued for rendering, then we have completed prerolling.
-  if (presentation_timestamp != kNoTimestamp())
+  if (current_presentation_timestamp != kNoTimestamp())
     prerolling_ = false;
 
   switch (status) {
@@ -447,8 +455,8 @@ void MediaDecoderJob::OnDecodeCompleted(
   };
 
   stop_decode_pending_ = false;
-  base::ResetAndReturn(&decode_cb_).Run(status, presentation_timestamp,
-                                        audio_output_bytes);
+  base::ResetAndReturn(&decode_cb_).Run(
+      status, current_presentation_timestamp, max_presentation_timestamp);
 }
 
 const AccessUnit& MediaDecoderJob::CurrentAccessUnit() const {