Skip to content

Commit

Permalink
media/gpu/test: EncodedDataHelper returns scoped_refptr<DecoderBuffer>
Browse files Browse the repository at this point in the history
EncodedDataHelper should return scoped_refptr<DecoderBuffer>
rather than std::string as this is the input format required
by VideoDecoder::Decode().

Bug: 1044816
Test: video.DecodeAccel.* on eve
Change-Id: Iac47f4e710954efa1dbb7f8d48cdd56bc0f9c963
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2032543
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: David Staessens <dstaessens@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737660}
  • Loading branch information
Hirokazu Honda authored and Commit Bot committed Feb 3, 2020
1 parent d51ae24 commit a00a991
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
31 changes: 16 additions & 15 deletions media/gpu/test/video_decode_accelerator_unittest_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@ bool EncodedDataHelper::IsNALHeader(const std::string& data, size_t pos) {
data[pos + 3] == 1;
}

std::string EncodedDataHelper::GetBytesForNextData() {
scoped_refptr<DecoderBuffer> EncodedDataHelper::GetNextBuffer() {
switch (VideoCodecProfileToVideoCodec(profile_)) {
case kCodecH264:
return GetBytesForNextFragment();
return GetNextFragment();
case kCodecVP8:
case kCodecVP9:
return GetBytesForNextFrame();
return GetNextFrame();
default:
NOTREACHED();
return std::string();
return nullptr;
}
}

std::string EncodedDataHelper::GetBytesForNextFragment() {
scoped_refptr<DecoderBuffer> EncodedDataHelper::GetNextFragment() {
if (next_pos_to_decode_ == 0) {
size_t skipped_fragments_count = 0;
if (!LookForSPS(&skipped_fragments_count)) {
next_pos_to_decode_ = 0;
return std::string();
return nullptr;
}
num_skipped_fragments_ += skipped_fragments_count;
}
Expand All @@ -66,7 +66,9 @@ std::string EncodedDataHelper::GetBytesForNextFragment() {

// Update next_pos_to_decode_.
next_pos_to_decode_ = next_nalu_pos;
return data_.substr(start_pos, next_nalu_pos - start_pos);
return DecoderBuffer::CopyFrom(
reinterpret_cast<const uint8_t*>(&data_[start_pos]),
next_nalu_pos - start_pos);
}

size_t EncodedDataHelper::GetBytesForNextNALU(size_t start_pos) {
Expand Down Expand Up @@ -98,43 +100,42 @@ bool EncodedDataHelper::LookForSPS(size_t* skipped_fragments_count) {
return false;
}

std::string EncodedDataHelper::GetBytesForNextFrame() {
scoped_refptr<DecoderBuffer> EncodedDataHelper::GetNextFrame() {
// Helpful description: http://wiki.multimedia.cx/index.php?title=IVF
constexpr size_t kIVFHeaderSize = 32;
constexpr size_t kIVFFrameHeaderSize = 12;

size_t pos = next_pos_to_decode_;
std::string bytes;

// Only IVF video files are supported. The first 4bytes of an IVF video file's
// header should be "DKIF".
if (pos == 0) {
if ((data_.size() < kIVFHeaderSize) || strncmp(&data_[0], "DKIF", 4) != 0) {
LOG(ERROR) << "Unexpected data encountered while parsing IVF header";
return bytes;
return nullptr;
}
pos = kIVFHeaderSize; // Skip IVF header.
}

// Read VP8/9 frame size from IVF header.
if (pos + kIVFFrameHeaderSize > data_.size()) {
LOG(ERROR) << "Unexpected data encountered while parsing IVF frame header";
return bytes;
return nullptr;
}
uint32_t frame_size = *reinterpret_cast<uint32_t*>(&data_[pos]);
const uint32_t frame_size = *reinterpret_cast<uint32_t*>(&data_[pos]);
pos += kIVFFrameHeaderSize; // Skip IVF frame header.

// Make sure we are not reading out of bounds.
if (pos + frame_size > data_.size()) {
LOG(ERROR) << "Unexpected data encountered while parsing IVF frame header";
next_pos_to_decode_ = data_.size();
return bytes;
return nullptr;
}
bytes.append(data_.substr(pos, frame_size));

// Update next_pos_to_decode_.
next_pos_to_decode_ = pos + frame_size;
return bytes;
return DecoderBuffer::CopyFrom(reinterpret_cast<const uint8_t*>(&data_[pos]),
frame_size);
}

// static
Expand Down
7 changes: 4 additions & 3 deletions media/gpu/test/video_decode_accelerator_unittest_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "base/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "base/threading/thread_checker.h"
#include "media/base/decoder_buffer.h"
#include "media/base/video_codecs.h"
#include "media/base/video_frame.h"
#include "media/base/video_types.h"
Expand All @@ -36,7 +37,7 @@ class EncodedDataHelper {
// Compute and return the next fragment to be sent to the decoder, starting
// from the current position in the stream, and advance the current position
// to after the returned fragment.
std::string GetBytesForNextData();
scoped_refptr<DecoderBuffer> GetNextBuffer();
static bool HasConfigInfo(const uint8_t* data,
size_t size,
VideoCodecProfile profile);
Expand All @@ -49,9 +50,9 @@ class EncodedDataHelper {

private:
// For h.264.
std::string GetBytesForNextFragment();
scoped_refptr<DecoderBuffer> GetNextFragment();
// For VP8/9.
std::string GetBytesForNextFrame();
scoped_refptr<DecoderBuffer> GetNextFrame();

// Helpers for GetBytesForNextFragment above.
size_t GetBytesForNextNALU(size_t pos);
Expand Down
19 changes: 8 additions & 11 deletions media/gpu/test/video_player/video_decoder_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,16 @@ void VideoDecoderClient::DecodeNextFragmentTask() {
return;
}

std::string fragment_bytes = encoded_data_helper_->GetBytesForNextData();
size_t fragment_size = fragment_bytes.size();
if (fragment_size == 0) {
LOG(ERROR) << "Stream fragment has size 0";
scoped_refptr<DecoderBuffer> bitstream_buffer =
encoded_data_helper_->GetNextBuffer();
if (!bitstream_buffer) {
LOG(ERROR) << "Failed to get next video stream data";
return;
}

scoped_refptr<DecoderBuffer> bitstream_buffer = DecoderBuffer::CopyFrom(
reinterpret_cast<const uint8_t*>(fragment_bytes.data()), fragment_size);
bitstream_buffer->set_timestamp(base::TimeTicks::Now().since_origin());
bool has_config_info = media::test::EncodedDataHelper::HasConfigInfo(
bitstream_buffer->data(), bitstream_buffer->data_size(),
video_->Profile());

VideoDecoder::DecodeCB decode_cb = base::BindOnce(
CallbackThunk<decltype(&VideoDecoderClient::DecodeDoneTask),
Expand All @@ -310,11 +310,8 @@ void VideoDecoderClient::DecodeNextFragmentTask() {
num_outstanding_decode_requests_++;

// Throw event when we encounter a config info in a H.264 stream.
if (media::test::EncodedDataHelper::HasConfigInfo(
reinterpret_cast<const uint8_t*>(fragment_bytes.data()),
fragment_size, video_->Profile())) {
if (has_config_info)
FireEvent(VideoPlayerEvent::kConfigInfo);
}
}

void VideoDecoderClient::FlushTask() {
Expand Down

0 comments on commit a00a991

Please sign in to comment.