Commit 7835114c authored by dmichael@chromium.org's avatar dmichael@chromium.org

Make DefaultDeleter for Video{De|En}codeAccelerator

This makes a specialization of base::DefaultDeleter so that scoped_ptr will
use Destroy() instead of the destructor. Without this, it seems wrong to
hold VideoDecodeAccelerator in a scoped_ptr, given that letting scoped_ptr
delete it via the destructor would be an error.

Also moves the destructors to protected, to prevent mistakes.

BUG=

Review URL: https://codereview.chromium.org/292183011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273860 0039d316-1c4b-4281-b951-d872f2087c98
parent 700e8f48
......@@ -459,9 +459,6 @@ void GpuVideoDecodeAccelerator::OnWillDestroyStub() {
stub_->channel()->RemoveRoute(host_route_id_);
stub_->RemoveDestructionObserver(this);
if (video_decode_accelerator_)
video_decode_accelerator_.release()->Destroy();
delete this;
}
......
......@@ -150,9 +150,6 @@ void GpuVideoEncodeAccelerator::OnWillDestroyStub() {
stub_->channel()->RemoveRoute(host_route_id_);
stub_->RemoveDestructionObserver(this);
if (encoder_)
encoder_.release()->Destroy();
delete this;
}
......
......@@ -8,8 +8,8 @@ namespace content {
VideoDecodeAcceleratorImpl::VideoDecodeAcceleratorImpl() {}
VideoDecodeAcceleratorImpl::~VideoDecodeAcceleratorImpl() {}
bool VideoDecodeAcceleratorImpl::CanDecodeOnIOThread() { return false; }
VideoDecodeAcceleratorImpl::~VideoDecodeAcceleratorImpl() {}
} // namespace content
......@@ -14,7 +14,6 @@ class CONTENT_EXPORT VideoDecodeAcceleratorImpl
: public media::VideoDecodeAccelerator {
public:
VideoDecodeAcceleratorImpl();
virtual ~VideoDecodeAcceleratorImpl();
// Returns true if VDA::Decode and VDA::Client callbacks can run on the IO
// thread. Otherwise they will run on the GPU child thread. The purpose of
......@@ -23,8 +22,29 @@ class CONTENT_EXPORT VideoDecodeAcceleratorImpl
// PictureReady should be run on the child thread if a picture is delivered
// the first time so it can be cleared.
virtual bool CanDecodeOnIOThread();
protected:
virtual ~VideoDecodeAcceleratorImpl();
};
} // namespace content
namespace base {
template <class T>
struct DefaultDeleter;
// Specialize DefaultDeleter so that scoped_ptr<VideoDecodeAcceleratorImpl>
// always uses "Destroy()" instead of trying to use the destructor.
template <>
struct DefaultDeleter<content::VideoDecodeAcceleratorImpl> {
public:
inline void operator()(void* video_decode_accelerator) const {
static_cast<content::VideoDecodeAcceleratorImpl*>(video_decode_accelerator)
->Destroy();
}
};
} // namespace base
#endif // CONTENT_COMMON_GPU_MEDIA_VIDEO_DECODE_ACCELERATOR_IMPL_H_
......@@ -773,7 +773,7 @@ void GLRenderingVDAClient::DeleteDecoder() {
if (decoder_deleted())
return;
weak_decoder_factory_.reset();
decoder_.release()->Destroy();
decoder_.reset();
STLClearObject(&encoded_data_);
for (std::set<int>::iterator it = outstanding_texture_ids_.begin();
it != outstanding_texture_ids_.end(); ++it) {
......
......@@ -584,7 +584,7 @@ void VEAClient::DestroyEncoder() {
DCHECK(thread_checker_.CalledOnValidThread());
if (!has_encoder())
return;
encoder_.release()->Destroy();
encoder_.reset();
}
double VEAClient::frames_per_second() {
......
......@@ -279,8 +279,7 @@ void RTCVideoEncoder::Impl::RequestEncodingParametersChange(uint32 bitrate,
void RTCVideoEncoder::Impl::Destroy() {
DVLOG(3) << "Impl::Destroy()";
DCHECK(thread_checker_.CalledOnValidThread());
if (video_encoder_)
video_encoder_.release()->Destroy();
video_encoder_.reset();
}
void RTCVideoEncoder::Impl::RequireBitstreamBuffers(
......@@ -400,8 +399,7 @@ void RTCVideoEncoder::Impl::NotifyError(
retval = WEBRTC_VIDEO_CODEC_ERROR;
}
if (video_encoder_)
video_encoder_.release()->Destroy();
video_encoder_.reset();
if (async_waiter_) {
SignalAsyncWaiter(retval);
......
......@@ -224,8 +224,7 @@ int32_t PPB_VideoDecoder_Impl::Reset(scoped_refptr<TrackedCallback> callback) {
void PPB_VideoDecoder_Impl::Destroy() {
FlushCommandBuffer();
if (decoder_)
decoder_.release()->Destroy();
decoder_.reset();
ppp_videodecoder_ = NULL;
::ppapi::PPB_VideoDecoder_Shared::Destroy();
......
......@@ -134,9 +134,7 @@ class LocalVideoEncodeAcceleratorClient
DCHECK(encoder_task_runner_);
DCHECK(encoder_task_runner_->RunsTasksOnCurrentThread());
if (video_encode_accelerator_) {
video_encode_accelerator_.release()->Destroy();
}
video_encode_accelerator_.reset();
}
void SetBitRate(uint32 bit_rate) {
......@@ -168,9 +166,7 @@ class LocalVideoEncodeAcceleratorClient
DCHECK(encoder_task_runner_->RunsTasksOnCurrentThread());
VLOG(1) << "ExternalVideoEncoder NotifyError: " << error;
if (video_encode_accelerator_) {
video_encode_accelerator_.release()->Destroy();
}
video_encode_accelerator_.reset();
cast_environment_->PostTask(
CastEnvironment::MAIN,
FROM_HERE,
......
......@@ -220,8 +220,7 @@ void GpuVideoDecoder::DestroyPictureBuffers(PictureBufferMap* buffers) {
void GpuVideoDecoder::DestroyVDA() {
DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
if (vda_)
vda_.release()->Destroy();
vda_.reset();
// Not destroying PictureBuffers in |picture_buffers_at_display_| yet, since
// their textures may still be in use by the user of this GpuVideoDecoder.
......
......@@ -9,3 +9,15 @@ namespace media {
VideoDecodeAccelerator::~VideoDecodeAccelerator() {}
}
namespace base {
void DefaultDeleter<media::VideoDecodeAccelerator>::operator()(
void* video_decode_accelerator) const {
static_cast<media::VideoDecodeAccelerator*>(video_decode_accelerator)->
Destroy();
}
} // namespace base
......@@ -20,8 +20,6 @@ namespace media {
// implement the backend of PPB_VideoDecode_Dev.
class MEDIA_EXPORT VideoDecodeAccelerator {
public:
virtual ~VideoDecodeAccelerator();
// Enumeration of potential errors generated by the API.
// Note: Keep these in sync with PP_VideoDecodeError_Dev. Also do not
// rearrange, reuse or remove values as they are used for gathering UMA
......@@ -133,8 +131,28 @@ class MEDIA_EXPORT VideoDecodeAccelerator {
// no more callbacks will be made on the client. Deletes |this|
// unconditionally, so make sure to drop all pointers to it!
virtual void Destroy() = 0;
protected:
// Do not delete directly; use Destroy() or own it with a scoped_ptr, which
// will Destroy() it properly by default.
virtual ~VideoDecodeAccelerator();
};
} // namespace media
namespace base {
template <class T>
struct DefaultDeleter;
// Specialize DefaultDeleter so that scoped_ptr<VideoDecodeAccelerator> always
// uses "Destroy()" instead of trying to use the destructor.
template <>
struct MEDIA_EXPORT DefaultDeleter<media::VideoDecodeAccelerator> {
public:
void operator()(void* video_decode_accelerator) const;
};
} // namespace base
#endif // MEDIA_VIDEO_VIDEO_DECODE_ACCELERATOR_H_
......@@ -9,3 +9,14 @@ namespace media {
VideoEncodeAccelerator::~VideoEncodeAccelerator() {}
} // namespace media
namespace base {
void DefaultDeleter<media::VideoEncodeAccelerator>::operator()(
void* video_encode_accelerator) const {
static_cast<media::VideoEncodeAccelerator*>(video_encode_accelerator)->
Destroy();
}
} // namespace base
......@@ -22,8 +22,6 @@ class VideoFrame;
// Video encoder interface.
class MEDIA_EXPORT VideoEncodeAccelerator {
public:
virtual ~VideoEncodeAccelerator();
// Specification of an encoding profile supported by an encoder.
struct SupportedProfile {
VideoCodecProfile profile;
......@@ -143,8 +141,28 @@ class MEDIA_EXPORT VideoEncodeAccelerator {
// this method returns no more callbacks will be made on the client. Deletes
// |this| unconditionally, so make sure to drop all pointers to it!
virtual void Destroy() = 0;
protected:
// Do not delete directly; use Destroy() or own it with a scoped_ptr, which
// will Destroy() it properly by default.
virtual ~VideoEncodeAccelerator();
};
} // namespace media
namespace base {
template <class T>
struct DefaultDeleter;
// Specialize DefaultDeleter so that scoped_ptr<VideoEncodeAccelerator> always
// uses "Destroy()" instead of trying to use the destructor.
template <>
struct MEDIA_EXPORT DefaultDeleter<media::VideoEncodeAccelerator> {
public:
void operator()(void* video_encode_accelerator) const;
};
} // namespace base
#endif // MEDIA_VIDEO_VIDEO_ENCODE_ACCELERATOR_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment