OLD | NEW |
| (Empty) |
1 // Copyright 2015 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_MEDIA_CODEC_VIDEO_DECODER_H_ | |
6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_VIDEO_DECODER_H_ | |
7 | |
8 #include <stddef.h> | |
9 | |
10 #include <set> | |
11 #include "base/macros.h" | |
12 #include "media/base/android/media_codec_decoder.h" | |
13 #include "ui/gfx/geometry/size.h" | |
14 #include "ui/gl/android/scoped_java_surface.h" | |
15 | |
16 namespace media { | |
17 | |
18 // Video decoder for MediaCodecPlayer | |
19 class MediaCodecVideoDecoder : public MediaCodecDecoder { | |
20 public: | |
21 // Typedefs for the notification callbacks | |
22 typedef base::Callback<void(const gfx::Size& video_size)> | |
23 VideoSizeChangedCallback; | |
24 | |
25 // For parameters see media_codec_decoder.h | |
26 // update_current_time_cb: callback that reports current playback time. | |
27 // Called for released output frame, | |
28 // video_size_changed_cb: reports the new video size, | |
29 // codec_created_cb: reports that video codec has been created. A controller | |
30 // class might use it to release more resources so that this | |
31 // decoder can use them. | |
32 MediaCodecVideoDecoder( | |
33 const scoped_refptr<base::SingleThreadTaskRunner>& media_runner, | |
34 FrameStatistics* frame_statistics, | |
35 const base::Closure& request_data_cb, | |
36 const base::Closure& starvation_cb, | |
37 const base::Closure& drained_requested_cb, | |
38 const base::Closure& stop_done_cb, | |
39 const base::Closure& waiting_for_decryption_key_cb, | |
40 const base::Closure& error_cb, | |
41 const SetTimeCallback& update_current_time_cb, | |
42 const VideoSizeChangedCallback& video_size_changed_cb); | |
43 ~MediaCodecVideoDecoder() override; | |
44 | |
45 const char* class_name() const override; | |
46 | |
47 bool HasStream() const override; | |
48 void SetDemuxerConfigs(const DemuxerConfigs& configs) override; | |
49 bool IsContentEncrypted() const override; | |
50 void ReleaseDecoderResources() override; | |
51 void ReleaseMediaCodec() override; | |
52 | |
53 // Stores the video surface to use with upcoming Configure() | |
54 void SetVideoSurface(gfx::ScopedJavaSurface surface); | |
55 | |
56 // Returns true if there is a video surface to use. | |
57 bool HasVideoSurface() const; | |
58 | |
59 // Sets whether protected surface is needed for the currently used DRM. | |
60 void SetProtectedSurfaceRequired(bool value); | |
61 | |
62 // Returns true if protected surface is needed. | |
63 bool IsProtectedSurfaceRequired() const; | |
64 | |
65 protected: | |
66 bool IsCodecReconfigureNeeded(const DemuxerConfigs& next) const override; | |
67 ConfigStatus ConfigureInternal(jobject media_crypto) override; | |
68 void AssociateCurrentTimeWithPTS(base::TimeDelta pts) override; | |
69 void DissociatePTSFromTime() override; | |
70 void OnOutputFormatChanged() override; | |
71 void Render(int buffer_index, | |
72 size_t offset, | |
73 size_t size, | |
74 RenderMode render_mode, | |
75 base::TimeDelta pts, | |
76 bool eos_encountered) override; | |
77 | |
78 int NumDelayedRenderTasks() const override; | |
79 void ReleaseDelayedBuffers() override; | |
80 | |
81 #ifndef NDEBUG | |
82 void VerifyUnitIsKeyFrame(const AccessUnit* unit) const override; | |
83 #endif | |
84 | |
85 private: | |
86 // A helper method that releases output buffers and does | |
87 // post-release checks. Might be called by Render() or posted | |
88 // for later execution. | |
89 void ReleaseOutputBuffer(int buffer_index, | |
90 base::TimeDelta pts, | |
91 bool render, | |
92 bool update_time, | |
93 bool eos_encountered); | |
94 | |
95 // Data. | |
96 | |
97 // Configuration received from demuxer | |
98 DemuxerConfigs configs_; | |
99 | |
100 // Video surface that we render to. | |
101 gfx::ScopedJavaSurface surface_; | |
102 | |
103 // Flags that indicates whether we need protected surface. | |
104 bool is_protected_surface_required_; | |
105 | |
106 // Reports current playback time to the callee. | |
107 SetTimeCallback update_current_time_cb_; | |
108 | |
109 // Informs the callee that video size is changed. | |
110 VideoSizeChangedCallback video_size_changed_cb_; | |
111 | |
112 // Current video size to be sent with |video_size_changed_cb_|. | |
113 gfx::Size video_size_; | |
114 | |
115 // Indices of output buffers that are posted for rendering. | |
116 std::set<int> delayed_buffers_; | |
117 | |
118 // Associate presentation timestamps with time. | |
119 base::TimeTicks start_time_ticks_; | |
120 base::TimeDelta start_pts_; | |
121 | |
122 // Mantain the last seen PTS for stand-alone EOS. | |
123 base::TimeDelta last_seen_pts_; | |
124 | |
125 DISALLOW_COPY_AND_ASSIGN(MediaCodecVideoDecoder); | |
126 }; | |
127 | |
128 } // namespace media | |
129 | |
130 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_VIDEO_DECODER_H_ | |
OLD | NEW |