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

Unified Diff: content/common/gpu/media/dxva_video_decode_accelerator_win.cc

Issue 1706023003: Moving the validation of bitstream_buffer into VDA implementations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compiling errors on windows Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/media/dxva_video_decode_accelerator_win.cc
diff --git a/content/common/gpu/media/dxva_video_decode_accelerator_win.cc b/content/common/gpu/media/dxva_video_decode_accelerator_win.cc
index a2f28f23374aaae70f7f3f3bbad64cae77ef1b65..1b0212c93feb2f4b3f322e13a1be54b84b4e45ea 100644
--- a/content/common/gpu/media/dxva_video_decode_accelerator_win.cc
+++ b/content/common/gpu/media/dxva_video_decode_accelerator_win.cc
@@ -246,21 +246,6 @@ static IMFSample* CreateInputSample(const uint8_t* stream,
return sample.Detach();
}
-static IMFSample* CreateSampleFromInputBuffer(
- const media::BitstreamBuffer& bitstream_buffer,
- uint32_t stream_size,
- DWORD alignment) {
- base::SharedMemory shm(bitstream_buffer.handle(), true);
- RETURN_ON_FAILURE(shm.Map(bitstream_buffer.size()),
- "Failed in base::SharedMemory::Map", NULL);
-
- return CreateInputSample(reinterpret_cast<const uint8_t*>(shm.memory()),
- bitstream_buffer.size(),
- std::min<uint32_t>(bitstream_buffer.size(),
- stream_size),
- alignment);
-}
-
// Helper function to create a COM object instance from a DLL. The alternative
// is to use the CoCreateInstance API which requires the COM apartment to be
// initialized which is not the case on the GPU main thread. We want to avoid
@@ -942,15 +927,28 @@ void DXVAVideoDecodeAccelerator::Decode(
const media::BitstreamBuffer& bitstream_buffer) {
DCHECK(main_thread_task_runner_->BelongsToCurrentThread());
+ // SharedMemory will take over the ownership of handle.
+ base::SharedMemory shm(bitstream_buffer.handle(), true);
+
State state = GetState();
RETURN_AND_NOTIFY_ON_FAILURE((state == kNormal || state == kStopped ||
state == kFlushing),
"Invalid state: " << state, ILLEGAL_STATE,);
+ if (bitstream_buffer.id() < 0) {
+ RETURN_AND_NOTIFY_ON_FAILURE(
+ false, "Invalid bitstream_buffer, id: " << bitstream_buffer.id(),
+ INVALID_ARGUMENT, );
+ }
base::win::ScopedComPtr<IMFSample> sample;
- sample.Attach(CreateSampleFromInputBuffer(bitstream_buffer,
- input_stream_info_.cbSize,
- input_stream_info_.cbAlignment));
+ RETURN_AND_NOTIFY_ON_FAILURE(shm.Map(bitstream_buffer.size()),
+ "Failed in base::SharedMemory::Map",
+ PLATFORM_FAILURE, );
+
+ sample.Attach(CreateInputSample(
+ reinterpret_cast<const uint8_t*>(shm.memory()), bitstream_buffer.size(),
+ std::min<uint32_t>(bitstream_buffer.size(), input_stream_info_.cbSize),
+ input_stream_info_.cbAlignment));
RETURN_AND_NOTIFY_ON_FAILURE(sample.get(), "Failed to create input sample",
PLATFORM_FAILURE, );

Powered by Google App Engine
This is Rietveld 408576698