Home | History | Annotate | Download | only in android
      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 MEDIA_BASE_ANDROID_VIDEO_DECODER_JOB_H_
      6 #define MEDIA_BASE_ANDROID_VIDEO_DECODER_JOB_H_
      7 
      8 #include <jni.h>
      9 
     10 #include "media/base/android/media_decoder_job.h"
     11 
     12 namespace media {
     13 
     14 class VideoCodecBridge;
     15 
     16 // Class for managing video decoding jobs.
     17 class VideoDecoderJob : public MediaDecoderJob {
     18  public:
     19   // Create a new VideoDecoderJob instance.
     20   // |request_data_cb| - Callback used to request more data for the decoder.
     21   // |request_resources_cb| - Callback used to request resources.
     22   // |on_demuxer_config_changed_cb| - Callback used to inform the caller that
     23   // demuxer config has changed.
     24   VideoDecoderJob(
     25       const base::Closure& request_data_cb,
     26       const base::Closure& request_resources_cb,
     27       const base::Closure& on_demuxer_config_changed_cb);
     28   virtual ~VideoDecoderJob();
     29 
     30   // Passes a java surface object to the codec. Returns true if the surface
     31   // can be used by the decoder, or false otherwise.
     32   bool SetVideoSurface(gfx::ScopedJavaSurface surface);
     33 
     34   // MediaDecoderJob implementation.
     35   virtual bool HasStream() const OVERRIDE;
     36   virtual void Flush() OVERRIDE;
     37   virtual void ReleaseDecoderResources() OVERRIDE;
     38   virtual void SetDemuxerConfigs(const DemuxerConfigs& configs) OVERRIDE;
     39 
     40   bool next_video_data_is_iframe() {
     41     return next_video_data_is_iframe_;
     42   }
     43 
     44   int output_width() const { return output_width_; }
     45   int output_height() const { return output_height_; }
     46 
     47  private:
     48   // MediaDecoderJob implementation.
     49   virtual void ReleaseOutputBuffer(
     50       int output_buffer_index,
     51       size_t size,
     52       bool render_output,
     53       base::TimeDelta current_presentation_timestamp,
     54       const ReleaseOutputCompletionCallback& callback) OVERRIDE;
     55   virtual bool ComputeTimeToRender() const OVERRIDE;
     56   virtual bool IsCodecReconfigureNeeded(
     57       const DemuxerConfigs& configs) const OVERRIDE;
     58   virtual bool AreDemuxerConfigsChanged(
     59       const DemuxerConfigs& configs) const OVERRIDE;
     60   virtual bool CreateMediaCodecBridgeInternal() OVERRIDE;
     61   virtual void CurrentDataConsumed(bool is_config_change) OVERRIDE;
     62   virtual bool UpdateOutputFormat() OVERRIDE;
     63 
     64   // Returns true if a protected surface is required for video playback.
     65   bool IsProtectedSurfaceRequired();
     66 
     67   // Video configs from the demuxer.
     68   VideoCodec video_codec_;
     69   int config_width_;
     70   int config_height_;
     71 
     72   // Video output format.
     73   int output_width_;
     74   int output_height_;
     75 
     76   // The surface object currently owned by the player.
     77   gfx::ScopedJavaSurface surface_;
     78 
     79   // Callbacks to inform the caller about decoder resources change.
     80   base::Closure request_resources_cb_;
     81   base::Closure release_resources_cb_;
     82 
     83   // Track whether the next access unit is an I-frame. The first access
     84   // unit after Flush() and CurrentDataConsumed(true) is guaranteed to be an
     85   // I-frame.
     86   bool next_video_data_is_iframe_;
     87 
     88   DISALLOW_COPY_AND_ASSIGN(VideoDecoderJob);
     89 };
     90 
     91 }  // namespace media
     92 
     93 #endif  // MEDIA_BASE_ANDROID_VIDEO_DECODER_JOB_H_
     94