Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: media/mojo/clients/mojo_renderer_impl.h

Issue 2075193002: Fixes use-after-free in MojoDemuxerStreamImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_MOJO_CLIENTS_MOJO_RENDERER_IMPL_H_ 5 #ifndef MEDIA_MOJO_CLIENTS_MOJO_RENDERER_IMPL_H_
6 #define MEDIA_MOJO_CLIENTS_MOJO_RENDERER_IMPL_H_ 6 #define MEDIA_MOJO_CLIENTS_MOJO_RENDERER_IMPL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "media/base/demuxer_stream.h"
11 #include "media/base/renderer.h" 12 #include "media/base/renderer.h"
12 #include "media/mojo/interfaces/renderer.mojom.h" 13 #include "media/mojo/interfaces/renderer.mojom.h"
13 #include "mojo/public/cpp/bindings/binding.h" 14 #include "mojo/public/cpp/bindings/binding.h"
14 15
15 namespace base { 16 namespace base {
16 class SingleThreadTaskRunner; 17 class SingleThreadTaskRunner;
17 } 18 }
18 19
19 namespace media { 20 namespace media {
20 21
21 class DemuxerStreamProvider; 22 class DemuxerStreamProvider;
23 class MojoDemuxerStreamImpl;
22 class VideoOverlayFactory; 24 class VideoOverlayFactory;
23 class VideoRendererSink; 25 class VideoRendererSink;
24 26
25 // A media::Renderer that proxies to a mojom::Renderer. That 27 // A media::Renderer that proxies to a mojom::Renderer. That
26 // mojom::Renderer proxies back to the MojoRendererImpl via the 28 // mojom::Renderer proxies back to the MojoRendererImpl via the
27 // mojom::RendererClient interface. 29 // mojom::RendererClient interface.
28 // 30 //
29 // This class can be created on any thread, where the |remote_renderer| is 31 // This class can be created on any thread, where the |remote_renderer| is
30 // connected and passed in the constructor. Then Initialize() will be called on 32 // connected and passed in the constructor. Then Initialize() will be called on
31 // the |task_runner| and starting from that point this class is bound to the 33 // the |task_runner| and starting from that point this class is bound to the
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 void OnVideoOpacityChange(bool opaque) override; 68 void OnVideoOpacityChange(bool opaque) override;
67 69
68 // Binds |remote_renderer_| to the mojo message pipe. Can be called multiple 70 // Binds |remote_renderer_| to the mojo message pipe. Can be called multiple
69 // times. If an error occurs during connection, OnConnectionError will be 71 // times. If an error occurs during connection, OnConnectionError will be
70 // called asynchronously. 72 // called asynchronously.
71 void BindRemoteRendererIfNeeded(); 73 void BindRemoteRendererIfNeeded();
72 74
73 // Callback for connection error on |remote_renderer_|. 75 // Callback for connection error on |remote_renderer_|.
74 void OnConnectionError(); 76 void OnConnectionError();
75 77
78 // Callback for connection error on |audio_stream_| and |video_stream_|.
79 void OnDemuxerStreamConnectionError(DemuxerStream::Type type);
80
76 // Callbacks for |remote_renderer_| methods. 81 // Callbacks for |remote_renderer_| methods.
77 void OnInitialized(media::RendererClient* client, bool success); 82 void OnInitialized(media::RendererClient* client, bool success);
78 void OnFlushed(); 83 void OnFlushed();
79 void OnCdmAttached(bool success); 84 void OnCdmAttached(bool success);
80 85
81 void CancelPendingCallbacks(); 86 void CancelPendingCallbacks();
82 87
83 // |task_runner| on which all methods are invoked, except for GetMediaTime(), 88 // |task_runner| on which all methods are invoked, except for GetMediaTime(),
84 // which can be called on any thread. 89 // which can be called on any thread.
85 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 90 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
86 91
87 // Overlay factory used to create overlays for video frames rendered 92 // Overlay factory used to create overlays for video frames rendered
88 // by the remote renderer. 93 // by the remote renderer.
89 std::unique_ptr<VideoOverlayFactory> video_overlay_factory_; 94 std::unique_ptr<VideoOverlayFactory> video_overlay_factory_;
90 95
91 // Video frame overlays are rendered onto this sink. 96 // Video frame overlays are rendered onto this sink.
92 // Rendering of a new overlay is only needed when video natural size changes. 97 // Rendering of a new overlay is only needed when video natural size changes.
93 VideoRendererSink* video_renderer_sink_ = nullptr; 98 VideoRendererSink* video_renderer_sink_ = nullptr;
94 99
95 // Provider of audio/video DemuxerStreams. Must be valid throughout the 100 // Provider of audio/video DemuxerStreams. Must be valid throughout the
96 // lifetime of |this|. 101 // lifetime of |this|.
97 DemuxerStreamProvider* demuxer_stream_provider_ = nullptr; 102 DemuxerStreamProvider* demuxer_stream_provider_ = nullptr;
98 103
99 // Client of |this| renderer passed in Initialize. 104 // Client of |this| renderer passed in Initialize.
100 media::RendererClient* client_ = nullptr; 105 media::RendererClient* client_ = nullptr;
101 106
107 // Mojo demuxer streams.
108 // Owned by MojoRendererImpl instead of remote mojom::Renderer
109 // becuase these demuxer streams need to be destroyed as soon as |this| is
110 // destroyed. The local demuxer streams returned by DemuxerStreamProvider
111 // cannot be used after |this| is destroyed.
112 // TODO(alokp): Add tests for MojoDemuxerStreamImpl.
113 std::unique_ptr<MojoDemuxerStreamImpl> audio_stream_;
114 std::unique_ptr<MojoDemuxerStreamImpl> video_stream_;
115
102 // This class is constructed on one thread and used exclusively on another 116 // This class is constructed on one thread and used exclusively on another
103 // thread. This member is used to safely pass the RendererPtr from one thread 117 // thread. This member is used to safely pass the RendererPtr from one thread
104 // to another. It is set in the constructor and is consumed in Initialize(). 118 // to another. It is set in the constructor and is consumed in Initialize().
105 mojom::RendererPtrInfo remote_renderer_info_; 119 mojom::RendererPtrInfo remote_renderer_info_;
106 120
107 // Remote Renderer, bound to |task_runner_| during Initialize(). 121 // Remote Renderer, bound to |task_runner_| during Initialize().
108 mojom::RendererPtr remote_renderer_; 122 mojom::RendererPtr remote_renderer_;
109 123
110 // Binding for RendererClient, bound to the |task_runner_|. 124 // Binding for RendererClient, bound to the |task_runner_|.
111 mojo::Binding<RendererClient> binding_; 125 mojo::Binding<RendererClient> binding_;
112 126
113 bool encountered_error_ = false; 127 bool encountered_error_ = false;
114 128
115 PipelineStatusCB init_cb_; 129 PipelineStatusCB init_cb_;
116 base::Closure flush_cb_; 130 base::Closure flush_cb_;
117 CdmAttachedCB cdm_attached_cb_; 131 CdmAttachedCB cdm_attached_cb_;
118 132
119 // Lock used to serialize access for |time_|. 133 // Lock used to serialize access for |time_|.
120 mutable base::Lock lock_; 134 mutable base::Lock lock_;
121 base::TimeDelta time_; 135 base::TimeDelta time_;
122 136
123 DISALLOW_COPY_AND_ASSIGN(MojoRendererImpl); 137 DISALLOW_COPY_AND_ASSIGN(MojoRendererImpl);
124 }; 138 };
125 139
126 } // namespace media 140 } // namespace media
127 141
128 #endif // MEDIA_MOJO_CLIENTS_MOJO_RENDERER_IMPL_H_ 142 #endif // MEDIA_MOJO_CLIENTS_MOJO_RENDERER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698