summaryrefslogtreecommitdiffstats
path: root/media/base/android/video_media_codec_decoder.h
blob: 03497269ba1175b8307240ff7638d15b0104ec16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_BASE_ANDROID_VIDEO_MEDIA_CODEC_DECODER_H_
#define MEDIA_BASE_ANDROID_VIDEO_MEDIA_CODEC_DECODER_H_

#include <stddef.h>

#include <set>
#include "base/macros.h"
#include "media/base/android/media_codec_decoder.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gl/android/scoped_java_surface.h"

namespace media {

// Video decoder for MediaCodecPlayer
class VideoMediaCodecDecoder : public MediaCodecDecoder {
 public:
  // Typedefs for the notification callbacks
  typedef base::Callback<void(const gfx::Size& video_size)>
      VideoSizeChangedCallback;

  // For parameters see media_codec_decoder.h
  // update_current_time_cb: callback that reports current playback time.
  //                         Called for released output frame,
  // video_size_changed_cb: reports the new video size,
  // codec_created_cb: reports that video codec has been created. A controller
  //                   class might use it to release more resources so that this
  //                   decoder can use them.
  VideoMediaCodecDecoder(
      const scoped_refptr<base::SingleThreadTaskRunner>& media_runner,
      FrameStatistics* frame_statistics,
      const base::Closure& request_data_cb,
      const base::Closure& starvation_cb,
      const base::Closure& drained_requested_cb,
      const base::Closure& stop_done_cb,
      const base::Closure& waiting_for_decryption_key_cb,
      const base::Closure& error_cb,
      const SetTimeCallback& update_current_time_cb,
      const VideoSizeChangedCallback& video_size_changed_cb);
  ~VideoMediaCodecDecoder() override;

  const char* class_name() const override;

  bool HasStream() const override;
  void SetDemuxerConfigs(const DemuxerConfigs& configs) override;
  bool IsContentEncrypted() const override;
  void ReleaseDecoderResources() override;
  void ReleaseMediaCodec() override;

  // Stores the video surface to use with upcoming Configure()
  void SetVideoSurface(gfx::ScopedJavaSurface surface);

  // Returns true if there is a video surface to use.
  bool HasVideoSurface() const;

  // Sets whether protected surface is needed for the currently used DRM.
  void SetProtectedSurfaceRequired(bool value);

  // Returns true if  protected surface is needed.
  bool IsProtectedSurfaceRequired() const;

 protected:
  bool IsCodecReconfigureNeeded(const DemuxerConfigs& next) const override;
  ConfigStatus ConfigureInternal(jobject media_crypto) override;
  void AssociateCurrentTimeWithPTS(base::TimeDelta pts) override;
  void DissociatePTSFromTime() override;
  void OnOutputFormatChanged() override;
  void Render(int buffer_index,
              size_t offset,
              size_t size,
              RenderMode render_mode,
              base::TimeDelta pts,
              bool eos_encountered) override;

  int NumDelayedRenderTasks() const override;
  void ReleaseDelayedBuffers() override;

#ifndef NDEBUG
  void VerifyUnitIsKeyFrame(const AccessUnit* unit) const override;
#endif

 private:
  // A helper method that releases output buffers and does
  // post-release checks. Might be called by Render() or posted
  // for later execution.
  void ReleaseOutputBuffer(int buffer_index,
                           base::TimeDelta pts,
                           bool render,
                           bool update_time,
                           bool eos_encountered);

  // Data.

  // Configuration received from demuxer
  DemuxerConfigs configs_;

  // Video surface that we render to.
  gfx::ScopedJavaSurface surface_;

  // Flags that indicates whether we need protected surface.
  bool is_protected_surface_required_;

  // Reports current playback time to the callee.
  SetTimeCallback update_current_time_cb_;

  // Informs the callee that video size is changed.
  VideoSizeChangedCallback video_size_changed_cb_;

  // Current video size to be sent with |video_size_changed_cb_|.
  gfx::Size video_size_;

  // Indices of output buffers that are posted for rendering.
  std::set<int> delayed_buffers_;

  // Associate presentation timestamps with time.
  base::TimeTicks start_time_ticks_;
  base::TimeDelta start_pts_;

  // Mantain the last seen PTS for stand-alone EOS.
  base::TimeDelta last_seen_pts_;

  DISALLOW_COPY_AND_ASSIGN(VideoMediaCodecDecoder);
};

}  // namespace media

#endif  // MEDIA_BASE_ANDROID_VIDEO_MEDIA_CODEC_DECODER_H_