summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorposciak@chromium.org <posciak@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-10 09:11:28 +0000
committerposciak@chromium.org <posciak@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-10 09:11:28 +0000
commitece777aed5f1b000467b9202abd193baf146319b (patch)
treed051b98038469881175b0abc6493bfeab5ca11c6
parentb885a70783f397c78e6da8b11eb58ba10e28af86 (diff)
downloadchromium_src-ece777aed5f1b000467b9202abd193baf146319b.zip
chromium_src-ece777aed5f1b000467b9202abd193baf146319b.tar.gz
chromium_src-ece777aed5f1b000467b9202abd193baf146319b.tar.bz2
Move H264Parser and H264BitReader to media/filters.
In preparation for wider usage in media code, move the H.264 parser and reader classes to media/filters from GPU-accelerated media locations, and into the media namespace. These classes have only been, up to now, used by hardware decode accelerators. Also, move their unittests along and make them a part of media_unittests, demoting H264ParserUnittest from being a standalone executable. While it was designed to be run on a set of streams from commandline, it should make more sense to run it more regularly (if only on just one stream), together with media tests, to prevent basic regressions, if it's to be used more widely than only in CrOS hardware acceleration classes. BUG=None TEST=Build VAVDA and vdaunittest for x86, build EVDA, vdaunittest and veaunittest for ARM. Also build and run media_unittests for both. Review URL: https://codereview.chromium.org/119153002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244132 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/common/gpu/media/h264_dpb.h5
-rw-r--r--content/common/gpu/media/v4l2_video_decode_accelerator.cc28
-rw-r--r--content/common/gpu/media/v4l2_video_decode_accelerator.h8
-rw-r--r--content/common/gpu/media/vaapi_h264_decoder.cc77
-rw-r--r--content/common/gpu/media/vaapi_h264_decoder.h24
-rw-r--r--content/common/gpu/media/video_encode_accelerator_unittest.cc20
-rw-r--r--content/content_common.gypi4
-rw-r--r--content/content_tests.gypi24
-rw-r--r--media/filters/h264_bit_reader.cc (renamed from content/common/gpu/media/h264_bit_reader.cc)25
-rw-r--r--media/filters/h264_bit_reader.h (renamed from content/common/gpu/media/h264_bit_reader.h)18
-rw-r--r--media/filters/h264_bit_reader_unittest.cc (renamed from content/common/gpu/media/h264_bit_reader_unittest.cc)9
-rw-r--r--media/filters/h264_parser.cc (renamed from content/common/gpu/media/h264_parser.cc)228
-rw-r--r--media/filters/h264_parser.h (renamed from content/common/gpu/media/h264_parser.h)57
-rw-r--r--media/filters/h264_parser_unittest.cc (renamed from content/common/gpu/media/h264_parser_unittest.cc)51
-rw-r--r--media/media.gyp6
15 files changed, 276 insertions, 308 deletions
diff --git a/content/common/gpu/media/h264_dpb.h b/content/common/gpu/media/h264_dpb.h
index fe15c70..29be0bc 100644
--- a/content/common/gpu/media/h264_dpb.h
+++ b/content/common/gpu/media/h264_dpb.h
@@ -12,7 +12,7 @@
#include "base/basictypes.h"
#include "base/memory/scoped_vector.h"
-#include "content/common/gpu/media/h264_parser.h"
+#include "media/filters/h264_parser.h"
namespace content {
@@ -55,7 +55,8 @@ struct H264Picture {
// memory management after finishing this picture.
bool long_term_reference_flag;
bool adaptive_ref_pic_marking_mode_flag;
- H264DecRefPicMarking ref_pic_marking[H264SliceHeader::kRefListSize];
+ media::H264DecRefPicMarking
+ ref_pic_marking[media::H264SliceHeader::kRefListSize];
typedef std::vector<H264Picture*> PtrVector;
};
diff --git a/content/common/gpu/media/v4l2_video_decode_accelerator.cc b/content/common/gpu/media/v4l2_video_decode_accelerator.cc
index 5d4f01a..e13f88e 100644
--- a/content/common/gpu/media/v4l2_video_decode_accelerator.cc
+++ b/content/common/gpu/media/v4l2_video_decode_accelerator.cc
@@ -18,8 +18,8 @@
#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/posix/eintr_wrapper.h"
-#include "content/common/gpu/media/h264_parser.h"
#include "content/common/gpu/media/v4l2_video_decode_accelerator.h"
+#include "media/filters/h264_parser.h"
#include "ui/gl/scoped_binders.h"
namespace content {
@@ -330,7 +330,7 @@ bool V4L2VideoDecodeAccelerator::Initialize(
// Initialize format-specific bits.
if (video_profile_ >= media::H264PROFILE_MIN &&
video_profile_ <= media::H264PROFILE_MAX) {
- decoder_h264_parser_.reset(new content::H264Parser());
+ decoder_h264_parser_.reset(new media::H264Parser());
}
if (!decoder_thread_.Start()) {
@@ -652,8 +652,8 @@ bool V4L2VideoDecodeAccelerator::AdvanceFrameFragment(
// For H264, we need to feed HW one frame at a time. This is going to take
// some parsing of our input stream.
decoder_h264_parser_->SetStream(data, size);
- content::H264NALU nalu;
- content::H264Parser::Result result;
+ media::H264NALU nalu;
+ media::H264Parser::Result result;
*endpos = 0;
// Keep on peeking the next NALs while they don't indicate a frame
@@ -661,17 +661,17 @@ bool V4L2VideoDecodeAccelerator::AdvanceFrameFragment(
for (;;) {
bool end_of_frame = false;
result = decoder_h264_parser_->AdvanceToNextNALU(&nalu);
- if (result == content::H264Parser::kInvalidStream ||
- result == content::H264Parser::kUnsupportedStream)
+ if (result == media::H264Parser::kInvalidStream ||
+ result == media::H264Parser::kUnsupportedStream)
return false;
- if (result == content::H264Parser::kEOStream) {
+ if (result == media::H264Parser::kEOStream) {
// We've reached the end of the buffer before finding a frame boundary.
decoder_partial_frame_pending_ = true;
return true;
}
switch (nalu.nal_unit_type) {
- case content::H264NALU::kNonIDRSlice:
- case content::H264NALU::kIDRSlice:
+ case media::H264NALU::kNonIDRSlice:
+ case media::H264NALU::kIDRSlice:
if (nalu.size < 1)
return false;
// For these two, if the "first_mb_in_slice" field is zero, start a
@@ -684,10 +684,10 @@ bool V4L2VideoDecodeAccelerator::AdvanceFrameFragment(
break;
}
break;
- case content::H264NALU::kSPS:
- case content::H264NALU::kPPS:
- case content::H264NALU::kEOSeq:
- case content::H264NALU::kEOStream:
+ case media::H264NALU::kSPS:
+ case media::H264NALU::kPPS:
+ case media::H264NALU::kEOSeq:
+ case media::H264NALU::kEOStream:
// These unconditionally signal a frame boundary.
end_of_frame = true;
break;
@@ -1415,7 +1415,7 @@ void V4L2VideoDecodeAccelerator::ResetDoneTask() {
// Reset format-specific bits.
if (video_profile_ >= media::H264PROFILE_MIN &&
video_profile_ <= media::H264PROFILE_MAX) {
- decoder_h264_parser_.reset(new content::H264Parser());
+ decoder_h264_parser_.reset(new media::H264Parser());
}
// Jobs drained, we're finished resetting.
diff --git a/content/common/gpu/media/v4l2_video_decode_accelerator.h b/content/common/gpu/media/v4l2_video_decode_accelerator.h
index 4e7b6e0..8b5ba49 100644
--- a/content/common/gpu/media/v4l2_video_decode_accelerator.h
+++ b/content/common/gpu/media/v4l2_video_decode_accelerator.h
@@ -26,11 +26,13 @@
namespace base {
class MessageLoopProxy;
-}
+} // namespace base
-namespace content {
+namespace media {
class H264Parser;
+} // namespace media
+namespace content {
// This class handles video accelerators directly through a V4L2 device exported
// by the hardware blocks.
//
@@ -350,7 +352,7 @@ class CONTENT_EXPORT V4L2VideoDecodeAccelerator
std::queue<linked_ptr<BitstreamBufferRef> > decoder_input_queue_;
// For H264 decode, hardware requires that we send it frame-sized chunks.
// We'll need to parse the stream.
- scoped_ptr<content::H264Parser> decoder_h264_parser_;
+ scoped_ptr<media::H264Parser> decoder_h264_parser_;
// Set if the decoder has a pending incomplete frame in an input buffer.
bool decoder_partial_frame_pending_;
diff --git a/content/common/gpu/media/vaapi_h264_decoder.cc b/content/common/gpu/media/vaapi_h264_decoder.cc
index 402369b..260a4e5 100644
--- a/content/common/gpu/media/vaapi_h264_decoder.cc
+++ b/content/common/gpu/media/vaapi_h264_decoder.cc
@@ -219,10 +219,10 @@ void VaapiH264Decoder::UnassignSurfaceFromPoC(int poc) {
}
bool VaapiH264Decoder::SendPPS() {
- const H264PPS* pps = parser_.GetPPS(curr_pps_id_);
+ const media::H264PPS* pps = parser_.GetPPS(curr_pps_id_);
DCHECK(pps);
- const H264SPS* sps = parser_.GetSPS(pps->seq_parameter_set_id);
+ const media::H264SPS* sps = parser_.GetSPS(pps->seq_parameter_set_id);
DCHECK(sps);
DCHECK(curr_pic_.get());
@@ -306,7 +306,7 @@ bool VaapiH264Decoder::SendPPS() {
}
bool VaapiH264Decoder::SendIQMatrix() {
- const H264PPS* pps = parser_.GetPPS(curr_pps_id_);
+ const media::H264PPS* pps = parser_.GetPPS(curr_pps_id_);
DCHECK(pps);
VAIQMatrixBufferH264 iq_matrix_buf;
@@ -323,7 +323,7 @@ bool VaapiH264Decoder::SendIQMatrix() {
iq_matrix_buf.ScalingList8x8[i][j] = pps->scaling_list8x8[i][j];
}
} else {
- const H264SPS* sps = parser_.GetSPS(pps->seq_parameter_set_id);
+ const media::H264SPS* sps = parser_.GetSPS(pps->seq_parameter_set_id);
DCHECK(sps);
for (int i = 0; i < 6; ++i) {
for (int j = 0; j < 16; ++j)
@@ -341,11 +341,11 @@ bool VaapiH264Decoder::SendIQMatrix() {
&iq_matrix_buf);
}
-bool VaapiH264Decoder::SendVASliceParam(H264SliceHeader* slice_hdr) {
- const H264PPS* pps = parser_.GetPPS(slice_hdr->pic_parameter_set_id);
+bool VaapiH264Decoder::SendVASliceParam(media::H264SliceHeader* slice_hdr) {
+ const media::H264PPS* pps = parser_.GetPPS(slice_hdr->pic_parameter_set_id);
DCHECK(pps);
- const H264SPS* sps = parser_.GetSPS(pps->seq_parameter_set_id);
+ const media::H264SPS* sps = parser_.GetSPS(pps->seq_parameter_set_id);
DCHECK(sps);
VASliceParameterBufferH264 slice_param;
@@ -440,7 +440,7 @@ bool VaapiH264Decoder::SendSliceData(const uint8* ptr, size_t size) {
non_const_ptr);
}
-bool VaapiH264Decoder::PrepareRefPicLists(H264SliceHeader* slice_hdr) {
+bool VaapiH264Decoder::PrepareRefPicLists(media::H264SliceHeader* slice_hdr) {
ref_pic_list0_.clear();
ref_pic_list1_.clear();
@@ -459,7 +459,7 @@ bool VaapiH264Decoder::PrepareRefPicLists(H264SliceHeader* slice_hdr) {
return true;
}
-bool VaapiH264Decoder::QueueSlice(H264SliceHeader* slice_hdr) {
+bool VaapiH264Decoder::QueueSlice(media::H264SliceHeader* slice_hdr) {
DCHECK(curr_pic_.get());
if (!PrepareRefPicLists(slice_hdr))
@@ -495,8 +495,7 @@ bool VaapiH264Decoder::DecodePicture() {
return true;
}
-
-bool VaapiH264Decoder::InitCurrPicture(H264SliceHeader* slice_hdr) {
+bool VaapiH264Decoder::InitCurrPicture(media::H264SliceHeader* slice_hdr) {
DCHECK(curr_pic_.get());
memset(curr_pic_.get(), 0, sizeof(H264Picture));
@@ -541,9 +540,10 @@ bool VaapiH264Decoder::InitCurrPicture(H264SliceHeader* slice_hdr) {
return true;
}
-bool VaapiH264Decoder::CalculatePicOrderCounts(H264SliceHeader* slice_hdr) {
+bool VaapiH264Decoder::CalculatePicOrderCounts(
+ media::H264SliceHeader* slice_hdr) {
DCHECK_NE(curr_sps_id_, -1);
- const H264SPS* sps = parser_.GetSPS(curr_sps_id_);
+ const media::H264SPS* sps = parser_.GetSPS(curr_sps_id_);
int pic_order_cnt_lsb = slice_hdr->pic_order_cnt_lsb;
curr_pic_->pic_order_cnt_lsb = pic_order_cnt_lsb;
@@ -750,7 +750,8 @@ struct LongTermPicNumAscCompare {
}
};
-void VaapiH264Decoder::ConstructReferencePicListsP(H264SliceHeader* slice_hdr) {
+void VaapiH264Decoder::ConstructReferencePicListsP(
+ media::H264SliceHeader* slice_hdr) {
// RefPicList0 (8.2.4.2.1) [[1] [2]], where:
// [1] shortterm ref pics sorted by descending pic_num,
// [2] longterm ref pics by ascending long_term_pic_num.
@@ -783,7 +784,8 @@ struct POCDescCompare {
}
};
-void VaapiH264Decoder::ConstructReferencePicListsB(H264SliceHeader* slice_hdr) {
+void VaapiH264Decoder::ConstructReferencePicListsB(
+ media::H264SliceHeader* slice_hdr) {
// RefPicList0 (8.2.4.2.3) [[1] [2] [3]], where:
// [1] shortterm ref pics with POC < curr_pic's POC sorted by descending POC,
// [2] shortterm ref pics with POC > curr_pic's POC by ascending POC,
@@ -886,11 +888,11 @@ static void ShiftRightAndInsert(H264Picture::PtrVector *v,
(*v)[from] = pic;
}
-bool VaapiH264Decoder::ModifyReferencePicList(H264SliceHeader *slice_hdr,
+bool VaapiH264Decoder::ModifyReferencePicList(media::H264SliceHeader* slice_hdr,
int list) {
int num_ref_idx_lX_active_minus1;
H264Picture::PtrVector* ref_pic_listx;
- H264ModificationOfPicNum* list_mod;
+ media::H264ModificationOfPicNum* list_mod;
// This can process either ref_pic_list0 or ref_pic_list1, depending on
// the list argument. Set up pointers to proper list to be processed here.
@@ -922,7 +924,7 @@ bool VaapiH264Decoder::ModifyReferencePicList(H264SliceHeader *slice_hdr,
int pic_num_lx;
bool done = false;
H264Picture* pic;
- for (int i = 0; i < H264SliceHeader::kRefListModSize && !done; ++i) {
+ for (int i = 0; i < media::H264SliceHeader::kRefListModSize && !done; ++i) {
switch (list_mod->modification_of_pic_nums_idc) {
case 0:
case 1:
@@ -954,7 +956,7 @@ bool VaapiH264Decoder::ModifyReferencePicList(H264SliceHeader *slice_hdr,
pic_num_lx = pic_num_lx_no_wrap;
DCHECK_LT(num_ref_idx_lX_active_minus1 + 1,
- H264SliceHeader::kRefListModSize);
+ media::H264SliceHeader::kRefListModSize);
pic = dpb_.GetShortRefPicByPicNum(pic_num_lx);
if (!pic) {
DVLOG(1) << "Malformed stream, no pic num " << pic_num_lx;
@@ -974,7 +976,7 @@ bool VaapiH264Decoder::ModifyReferencePicList(H264SliceHeader *slice_hdr,
case 2:
// Modify long term reference picture position.
DCHECK_LT(num_ref_idx_lX_active_minus1 + 1,
- H264SliceHeader::kRefListModSize);
+ media::H264SliceHeader::kRefListModSize);
pic = dpb_.GetLongRefPicByLongTermPicNum(list_mod->long_term_pic_num);
if (!pic) {
DVLOG(1) << "Malformed stream, no pic num "
@@ -1074,7 +1076,7 @@ bool VaapiH264Decoder::Flush() {
return true;
}
-bool VaapiH264Decoder::StartNewFrame(H264SliceHeader* slice_hdr) {
+bool VaapiH264Decoder::StartNewFrame(media::H264SliceHeader* slice_hdr) {
// TODO posciak: add handling of max_num_ref_frames per spec.
// If the new frame is an IDR, output what's left to output and clear DPB
@@ -1120,7 +1122,8 @@ bool VaapiH264Decoder::HandleMemoryManagementOps() {
// 8.2.5.4
for (unsigned int i = 0; i < arraysize(curr_pic_->ref_pic_marking); ++i) {
// Code below does not support interlaced stream (per-field pictures).
- H264DecRefPicMarking* ref_pic_marking = &curr_pic_->ref_pic_marking[i];
+ media::H264DecRefPicMarking* ref_pic_marking =
+ &curr_pic_->ref_pic_marking[i];
H264Picture* to_mark;
int pic_num_x;
@@ -1397,7 +1400,7 @@ static int LevelToMaxDpbMbs(int level) {
}
bool VaapiH264Decoder::ProcessSPS(int sps_id, bool* need_new_buffers) {
- const H264SPS* sps = parser_.GetSPS(sps_id);
+ const media::H264SPS* sps = parser_.GetSPS(sps_id);
DCHECK(sps);
DVLOG(4) << "Processing SPS";
@@ -1461,7 +1464,7 @@ bool VaapiH264Decoder::ProcessSPS(int sps_id, bool* need_new_buffers) {
}
bool VaapiH264Decoder::ProcessPPS(int pps_id) {
- const H264PPS* pps = parser_.GetPPS(pps_id);
+ const media::H264PPS* pps = parser_.GetPPS(pps_id);
DCHECK(pps);
curr_pps_id_ = pps->pic_parameter_set_id;
@@ -1480,7 +1483,7 @@ bool VaapiH264Decoder::FinishPrevFrameIfPresent() {
return true;
}
-bool VaapiH264Decoder::ProcessSlice(H264SliceHeader* slice_hdr) {
+bool VaapiH264Decoder::ProcessSlice(media::H264SliceHeader* slice_hdr) {
prev_frame_num_ = frame_num_;
frame_num_ = slice_hdr->frame_num;
@@ -1530,8 +1533,8 @@ void VaapiH264Decoder::SetStream(uint8* ptr, size_t size, int32 input_id) {
}
VaapiH264Decoder::DecResult VaapiH264Decoder::Decode() {
- H264Parser::Result par_res;
- H264NALU nalu;
+ media::H264Parser::Result par_res;
+ media::H264NALU nalu;
DCHECK_NE(state_, kError);
while (1) {
@@ -1547,20 +1550,20 @@ VaapiH264Decoder::DecResult VaapiH264Decoder::Decode() {
}
par_res = parser_.AdvanceToNextNALU(&nalu);
- if (par_res == H264Parser::kEOStream)
+ if (par_res == media::H264Parser::kEOStream)
return kRanOutOfStreamData;
- else if (par_res != H264Parser::kOk)
+ else if (par_res != media::H264Parser::kOk)
SET_ERROR_AND_RETURN();
DVLOG(4) << "NALU found: " << static_cast<int>(nalu.nal_unit_type);
switch (nalu.nal_unit_type) {
- case H264NALU::kNonIDRSlice:
+ case media::H264NALU::kNonIDRSlice:
// We can't resume from a non-IDR slice.
if (state_ != kDecoding)
break;
// else fallthrough
- case H264NALU::kIDRSlice: {
+ case media::H264NALU::kIDRSlice: {
// TODO(posciak): the IDR may require an SPS that we don't have
// available. For now we'd fail if that happens, but ideally we'd like
// to keep going until the next SPS in the stream.
@@ -1570,10 +1573,10 @@ VaapiH264Decoder::DecResult VaapiH264Decoder::Decode() {
}
// If after reset, we should be able to recover from an IDR.
- H264SliceHeader slice_hdr;
+ media::H264SliceHeader slice_hdr;
par_res = parser_.ParseSliceHeader(nalu, &slice_hdr);
- if (par_res != H264Parser::kOk)
+ if (par_res != media::H264Parser::kOk)
SET_ERROR_AND_RETURN();
if (!ProcessSlice(&slice_hdr))
@@ -1583,14 +1586,14 @@ VaapiH264Decoder::DecResult VaapiH264Decoder::Decode() {
break;
}
- case H264NALU::kSPS: {
+ case media::H264NALU::kSPS: {
int sps_id;
if (!FinishPrevFrameIfPresent())
SET_ERROR_AND_RETURN();
par_res = parser_.ParseSPS(&sps_id);
- if (par_res != H264Parser::kOk)
+ if (par_res != media::H264Parser::kOk)
SET_ERROR_AND_RETURN();
bool need_new_buffers = false;
@@ -1609,7 +1612,7 @@ VaapiH264Decoder::DecResult VaapiH264Decoder::Decode() {
break;
}
- case H264NALU::kPPS: {
+ case media::H264NALU::kPPS: {
if (state_ != kDecoding)
break;
@@ -1619,7 +1622,7 @@ VaapiH264Decoder::DecResult VaapiH264Decoder::Decode() {
SET_ERROR_AND_RETURN();
par_res = parser_.ParsePPS(&pps_id);
- if (par_res != H264Parser::kOk)
+ if (par_res != media::H264Parser::kOk)
SET_ERROR_AND_RETURN();
if (!ProcessPPS(pps_id))
diff --git a/content/common/gpu/media/vaapi_h264_decoder.h b/content/common/gpu/media/vaapi_h264_decoder.h
index 3bc63d3..e23d913 100644
--- a/content/common/gpu/media/vaapi_h264_decoder.h
+++ b/content/common/gpu/media/vaapi_h264_decoder.h
@@ -16,9 +16,9 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "content/common/gpu/media/h264_dpb.h"
-#include "content/common/gpu/media/h264_parser.h"
#include "content/common/gpu/media/vaapi_wrapper.h"
#include "media/base/limits.h"
+#include "media/filters/h264_parser.h"
namespace content {
@@ -130,26 +130,26 @@ class VaapiH264Decoder {
// Process H264 stream structures.
bool ProcessSPS(int sps_id, bool* need_new_buffers);
bool ProcessPPS(int pps_id);
- bool ProcessSlice(H264SliceHeader* slice_hdr);
+ bool ProcessSlice(media::H264SliceHeader* slice_hdr);
// Initialize the current picture according to data in |slice_hdr|.
- bool InitCurrPicture(H264SliceHeader* slice_hdr);
+ bool InitCurrPicture(media::H264SliceHeader* slice_hdr);
// Calculate picture order counts for the new picture
// on initialization of a new frame (see spec).
- bool CalculatePicOrderCounts(H264SliceHeader* slice_hdr);
+ bool CalculatePicOrderCounts(media::H264SliceHeader* slice_hdr);
// Update PicNum values in pictures stored in DPB on creation of new
// frame (see spec).
void UpdatePicNums();
// Prepare reference picture lists (ref_pic_list[01]_).
- bool PrepareRefPicLists(H264SliceHeader* slice_hdr);
+ bool PrepareRefPicLists(media::H264SliceHeader* slice_hdr);
// Construct initial reference picture lists for use in decoding of
// P and B pictures (see 8.2.4 in spec).
- void ConstructReferencePicListsP(H264SliceHeader* slice_hdr);
- void ConstructReferencePicListsB(H264SliceHeader* slice_hdr);
+ void ConstructReferencePicListsP(media::H264SliceHeader* slice_hdr);
+ void ConstructReferencePicListsB(media::H264SliceHeader* slice_hdr);
// Helper functions for reference list construction, per spec.
int PicNumF(H264Picture *pic);
@@ -159,7 +159,7 @@ class VaapiH264Decoder {
// specified in spec (8.2.4).
//
// |list| indicates list number and should be either 0 or 1.
- bool ModifyReferencePicList(H264SliceHeader *slice_hdr, int list);
+ bool ModifyReferencePicList(media::H264SliceHeader* slice_hdr, int list);
// Perform reference picture memory management operations (marking/unmarking
// of reference pictures, long term picture management, discarding, etc.).
@@ -168,7 +168,7 @@ class VaapiH264Decoder {
void ReferencePictureMarking();
// Start processing a new frame.
- bool StartNewFrame(H264SliceHeader* slice_hdr);
+ bool StartNewFrame(media::H264SliceHeader* slice_hdr);
// All data for a frame received, process it and decode.
bool FinishPrevFrameIfPresent();
@@ -187,9 +187,9 @@ class VaapiH264Decoder {
// These queue up data for HW decoder to be committed on running HW decode.
bool SendPPS();
bool SendIQMatrix();
- bool SendVASliceParam(H264SliceHeader* slice_hdr);
+ bool SendVASliceParam(media::H264SliceHeader* slice_hdr);
bool SendSliceData(const uint8* ptr, size_t size);
- bool QueueSlice(H264SliceHeader* slice_hdr);
+ bool QueueSlice(media::H264SliceHeader* slice_hdr);
// Helper methods for filling HW structures.
void FillVAPicture(VAPictureH264 *va_pic, H264Picture* pic);
@@ -223,7 +223,7 @@ class VaapiH264Decoder {
State state_;
// Parser in use.
- H264Parser parser_;
+ media::H264Parser parser_;
// DPB in use.
H264DPB dpb_;
diff --git a/content/common/gpu/media/video_encode_accelerator_unittest.cc b/content/common/gpu/media/video_encode_accelerator_unittest.cc
index 414925c..0bc4662 100644
--- a/content/common/gpu/media/video_encode_accelerator_unittest.cc
+++ b/content/common/gpu/media/video_encode_accelerator_unittest.cc
@@ -13,10 +13,10 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "content/common/gpu/media/exynos_video_encode_accelerator.h"
-#include "content/common/gpu/media/h264_parser.h"
#include "content/common/gpu/media/video_accelerator_unittest_helpers.h"
#include "media/base/bind_to_current_loop.h"
#include "media/base/bitstream_buffer.h"
+#include "media/filters/h264_parser.h"
#include "media/video/video_encode_accelerator.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -181,7 +181,7 @@ class VEAClient : public VideoEncodeAccelerator::Client {
// Byte size of the encoded stream (for bitrate calculation).
size_t encoded_stream_size_;
- content::H264Parser h264_parser_;
+ media::H264Parser h264_parser_;
// All methods of this class should be run on the same thread.
base::ThreadChecker thread_checker_;
@@ -319,17 +319,17 @@ void VEAClient::BitstreamBufferReady(int32 bitstream_buffer_id,
bool seen_idr_in_this_buffer = false;
while (1) {
- content::H264NALU nalu;
- content::H264Parser::Result result;
+ media::H264NALU nalu;
+ media::H264Parser::Result result;
result = h264_parser_.AdvanceToNextNALU(&nalu);
- if (result == content::H264Parser::kEOStream)
+ if (result == media::H264Parser::kEOStream)
break;
- ASSERT_EQ(result, content::H264Parser::kOk);
+ ASSERT_EQ(result, media::H264Parser::kOk);
switch (nalu.nal_unit_type) {
- case content::H264NALU::kIDRSlice:
+ case media::H264NALU::kIDRSlice:
ASSERT_TRUE(seen_sps_);
ASSERT_TRUE(seen_pps_);
seen_idr_ = seen_idr_in_this_buffer = true;
@@ -337,7 +337,7 @@ void VEAClient::BitstreamBufferReady(int32 bitstream_buffer_id,
// got a frame in time or not.
keyframe_requested_at_ = kMaxFrameNum;
// fallthrough
- case content::H264NALU::kNonIDRSlice:
+ case media::H264NALU::kNonIDRSlice:
ASSERT_TRUE(seen_idr_);
++num_encoded_slices_;
@@ -354,10 +354,10 @@ void VEAClient::BitstreamBufferReady(int32 bitstream_buffer_id,
EXPECT_LE(num_encoded_slices_,
keyframe_requested_at_ + kMaxKeyframeDelay);
break;
- case content::H264NALU::kSPS:
+ case media::H264NALU::kSPS:
seen_sps_ = true;
break;
- case content::H264NALU::kPPS:
+ case media::H264NALU::kPPS:
ASSERT_TRUE(seen_sps_);
seen_pps_ = true;
break;
diff --git a/content/content_common.gypi b/content/content_common.gypi
index ee124b2..4b88762 100644
--- a/content/content_common.gypi
+++ b/content/content_common.gypi
@@ -245,10 +245,6 @@
'common/gpu/media/gpu_video_decode_accelerator.h',
'common/gpu/media/gpu_video_encode_accelerator.cc',
'common/gpu/media/gpu_video_encode_accelerator.h',
- 'common/gpu/media/h264_bit_reader.cc',
- 'common/gpu/media/h264_bit_reader.h',
- 'common/gpu/media/h264_parser.cc',
- 'common/gpu/media/h264_parser.h',
'common/gpu/media/video_decode_accelerator_impl.cc',
'common/gpu/media/video_decode_accelerator_impl.h',
'common/gpu/stream_texture_manager_android.cc',
diff --git a/content/content_tests.gypi b/content/content_tests.gypi
index 7a12314..d3ead29 100644
--- a/content/content_tests.gypi
+++ b/content/content_tests.gypi
@@ -1321,30 +1321,6 @@
},
]
}],
- ['chromeos == 1 or OS == "linux"', {
- 'targets': [
- {
- 'target_name': 'h264_parser_unittest',
- 'type': 'executable',
- 'dependencies': [
- 'content.gyp:content_common',
- '../base/base.gyp:base',
- '../testing/gtest.gyp:gtest',
- ],
- 'sources': [
- 'common/gpu/media/h264_bit_reader_unittest.cc',
- 'common/gpu/media/h264_parser_unittest.cc',
- ],
- 'conditions': [
- ['linux_use_tcmalloc==1', {
- 'dependencies': [
- '../base/allocator/allocator.gyp:allocator',
- ],
- }],
- ],
- }
- ],
- }],
# Special target to wrap a gtest_target_type==shared_library
# content_unittests into an android apk for execution.
# See base.gyp for TODO(jrg)s about this strategy.
diff --git a/content/common/gpu/media/h264_bit_reader.cc b/media/filters/h264_bit_reader.cc
index dbeb4db..9894d97 100644
--- a/content/common/gpu/media/h264_bit_reader.cc
+++ b/media/filters/h264_bit_reader.cc
@@ -1,17 +1,19 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/common/gpu/media/h264_bit_reader.h"
#include "base/logging.h"
+#include "media/filters/h264_bit_reader.h"
-namespace content {
+namespace media {
H264BitReader::H264BitReader()
- : data_(NULL), bytes_left_(0), curr_byte_(0),
- num_remaining_bits_in_curr_byte_(0), prev_two_bytes_(0),
- emulation_prevention_bytes_(0) {
-}
+ : data_(NULL),
+ bytes_left_(0),
+ curr_byte_(0),
+ num_remaining_bits_in_curr_byte_(0),
+ prev_two_bytes_(0),
+ emulation_prevention_bytes_(0) {}
H264BitReader::~H264BitReader() {}
@@ -62,7 +64,7 @@ bool H264BitReader::UpdateCurrByte() {
// Read |num_bits| (1 to 31 inclusive) from the stream and return them
// in |out|, with first bit in the stream as MSB in |out| at position
// (|num_bits| - 1).
-bool H264BitReader::ReadBits(int num_bits, int *out) {
+bool H264BitReader::ReadBits(int num_bits, int* out) {
int bits_left = num_bits;
*out = 0;
DCHECK(num_bits <= 31);
@@ -91,7 +93,7 @@ bool H264BitReader::HasMoreRBSPData() {
// Make sure we have more bits, if we are at 0 bits in current byte
// and updating current byte fails, we don't have more data anyway.
if (num_remaining_bits_in_curr_byte_ == 0 && !UpdateCurrByte())
- return false;
+ return false;
// On last byte?
if (bytes_left_)
@@ -104,9 +106,8 @@ bool H264BitReader::HasMoreRBSPData() {
((1 << (num_remaining_bits_in_curr_byte_ - 1)) - 1)) != 0;
}
-size_t H264BitReader::NumEmulationPreventionBytesRead()
-{
+size_t H264BitReader::NumEmulationPreventionBytesRead() {
return emulation_prevention_bytes_;
}
-} // namespace content
+} // namespace media
diff --git a/content/common/gpu/media/h264_bit_reader.h b/media/filters/h264_bit_reader.h
index a2d32b5..01cfd74 100644
--- a/content/common/gpu/media/h264_bit_reader.h
+++ b/media/filters/h264_bit_reader.h
@@ -1,24 +1,24 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This file contains an implementation of an H264 Annex-B video stream parser.
-#ifndef CONTENT_COMMON_GPU_MEDIA_H264_BIT_READER_H_
-#define CONTENT_COMMON_GPU_MEDIA_H264_BIT_READER_H_
+#ifndef MEDIA_FILTERS_H264_BIT_READER_H_
+#define MEDIA_FILTERS_H264_BIT_READER_H_
#include <sys/types.h>
#include "base/basictypes.h"
-#include "content/common/content_export.h"
+#include "media/base/media_export.h"
-namespace content {
+namespace media {
// A class to provide bit-granularity reading of H.264 streams.
// This is not a generic bit reader class, as it takes into account
// H.264 stream-specific constraints, such as skipping emulation-prevention
// bytes and stop bits. See spec for more details.
-class CONTENT_EXPORT H264BitReader {
+class MEDIA_EXPORT H264BitReader {
public:
H264BitReader();
~H264BitReader();
@@ -35,7 +35,7 @@ class CONTENT_EXPORT H264BitReader {
// |num_bits| may be 1-32, inclusive.
// Return false if the given number of bits cannot be read (not enough
// bits in the stream), true otherwise.
- bool ReadBits(int num_bits, int *out);
+ bool ReadBits(int num_bits, int* out);
// Return the number of bits left in the stream.
off_t NumBitsLeft();
@@ -74,6 +74,6 @@ class CONTENT_EXPORT H264BitReader {
DISALLOW_COPY_AND_ASSIGN(H264BitReader);
};
-} // namespace content
+} // namespace media
-#endif // CONTENT_COMMON_GPU_MEDIA_H264_BIT_READER_H_
+#endif // MEDIA_FILTERS_H264_BIT_READER_H_
diff --git a/content/common/gpu/media/h264_bit_reader_unittest.cc b/media/filters/h264_bit_reader_unittest.cc
index a02a21c..e12e75e 100644
--- a/content/common/gpu/media/h264_bit_reader_unittest.cc
+++ b/media/filters/h264_bit_reader_unittest.cc
@@ -1,12 +1,11 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "media/filters/h264_bit_reader.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "content/common/gpu/media/h264_bit_reader.h"
-
-using content::H264BitReader;
+namespace media {
TEST(H264BitReaderTest, ReadStreamWithoutEscapeAndTrailingZeroBytes) {
H264BitReader reader;
@@ -70,3 +69,5 @@ TEST(H264BitReaderTest, StopBitOccupyFullByte) {
EXPECT_EQ(reader.NumBitsLeft(), 8);
EXPECT_FALSE(reader.HasMoreRBSPData());
}
+
+} // namespace media
diff --git a/content/common/gpu/media/h264_parser.cc b/media/filters/h264_parser.cc
index 177668b..67c2fe5 100644
--- a/content/common/gpu/media/h264_parser.cc
+++ b/media/filters/h264_parser.cc
@@ -1,14 +1,14 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/common/gpu/media/h264_parser.h"
-
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/stl_util.h"
-namespace content {
+#include "media/filters/h264_parser.h"
+
+namespace media {
bool H264SliceHeader::IsPSlice() const {
return (slice_type % 5 == kPSlice);
@@ -50,59 +50,61 @@ H264SEIMessage::H264SEIMessage() {
memset(this, 0, sizeof(*this));
}
-#define READ_BITS_OR_RETURN(num_bits, out) \
-do { \
- int _out; \
- if (!br_.ReadBits(num_bits, &_out)) { \
- DVLOG(1) << "Error in stream: unexpected EOS while trying to read " #out; \
- return kInvalidStream; \
- } \
- *out = _out; \
-} while (0)
-
-#define READ_BOOL_OR_RETURN(out) \
-do { \
- int _out; \
- if (!br_.ReadBits(1, &_out)) { \
- DVLOG(1) << "Error in stream: unexpected EOS while trying to read " #out; \
- return kInvalidStream; \
- } \
- *out = _out != 0; \
-} while (0)
-
-#define READ_UE_OR_RETURN(out) \
-do { \
- if (ReadUE(out) != kOk) { \
- DVLOG(1) << "Error in stream: invalid value while trying to read " #out; \
- return kInvalidStream; \
- } \
-} while (0)
-
-#define READ_SE_OR_RETURN(out) \
-do { \
- if (ReadSE(out) != kOk) { \
- DVLOG(1) << "Error in stream: invalid value while trying to read " #out; \
- return kInvalidStream; \
- } \
-} while (0)
-
-#define IN_RANGE_OR_RETURN(val, min, max) \
-do { \
- if ((val) < (min) || (val) > (max)) { \
- DVLOG(1) << "Error in stream: invalid value, expected " #val " to be" \
- << " in range [" << (min) << ":" << (max) << "]" \
- << " found " << (val) << " instead"; \
- return kInvalidStream; \
- } \
-} while (0)
-
-#define TRUE_OR_RETURN(a) \
-do { \
- if (!(a)) { \
- DVLOG(1) << "Error in stream: invalid value, expected " << #a; \
- return kInvalidStream; \
- } \
-} while (0)
+#define READ_BITS_OR_RETURN(num_bits, out) \
+ do { \
+ int _out; \
+ if (!br_.ReadBits(num_bits, &_out)) { \
+ DVLOG(1) \
+ << "Error in stream: unexpected EOS while trying to read " #out; \
+ return kInvalidStream; \
+ } \
+ *out = _out; \
+ } while (0)
+
+#define READ_BOOL_OR_RETURN(out) \
+ do { \
+ int _out; \
+ if (!br_.ReadBits(1, &_out)) { \
+ DVLOG(1) \
+ << "Error in stream: unexpected EOS while trying to read " #out; \
+ return kInvalidStream; \
+ } \
+ *out = _out != 0; \
+ } while (0)
+
+#define READ_UE_OR_RETURN(out) \
+ do { \
+ if (ReadUE(out) != kOk) { \
+ DVLOG(1) << "Error in stream: invalid value while trying to read " #out; \
+ return kInvalidStream; \
+ } \
+ } while (0)
+
+#define READ_SE_OR_RETURN(out) \
+ do { \
+ if (ReadSE(out) != kOk) { \
+ DVLOG(1) << "Error in stream: invalid value while trying to read " #out; \
+ return kInvalidStream; \
+ } \
+ } while (0)
+
+#define IN_RANGE_OR_RETURN(val, min, max) \
+ do { \
+ if ((val) < (min) || (val) > (max)) { \
+ DVLOG(1) << "Error in stream: invalid value, expected " #val " to be" \
+ << " in range [" << (min) << ":" << (max) << "]" \
+ << " found " << (val) << " instead"; \
+ return kInvalidStream; \
+ } \
+ } while (0)
+
+#define TRUE_OR_RETURN(a) \
+ do { \
+ if (!(a)) { \
+ DVLOG(1) << "Error in stream: invalid value, expected " << #a; \
+ return kInvalidStream; \
+ } \
+ } while (0)
H264Parser::H264Parser() {
Reset();
@@ -248,7 +250,7 @@ H264Parser::Result H264Parser::ReadSE(int* val) {
return kOk;
}
-H264Parser::Result H264Parser::AdvanceToNextNALU(H264NALU *nalu) {
+H264Parser::Result H264Parser::AdvanceToNextNALU(H264NALU* nalu) {
int data;
off_t off_to_nalu_start;
@@ -291,22 +293,22 @@ H264Parser::Result H264Parser::AdvanceToNextNALU(H264NALU *nalu) {
// Default scaling lists (per spec).
static const int kDefault4x4Intra[kH264ScalingList4x4Length] = {
- 6, 13, 13, 20, 20, 20, 28, 28, 28, 28, 32, 32, 32, 37, 37, 42, };
+ 6, 13, 13, 20, 20, 20, 28, 28, 28, 28, 32, 32, 32, 37, 37, 42, };
static const int kDefault4x4Inter[kH264ScalingList4x4Length] = {
- 10, 14, 14, 20, 20, 20, 24, 24, 24, 24, 27, 27, 27, 30, 30, 34, };
+ 10, 14, 14, 20, 20, 20, 24, 24, 24, 24, 27, 27, 27, 30, 30, 34, };
static const int kDefault8x8Intra[kH264ScalingList8x8Length] = {
- 6, 10, 10, 13, 11, 13, 16, 16, 16, 16, 18, 18, 18, 18, 18, 23,
- 23, 23, 23, 23, 23, 25, 25, 25, 25, 25, 25, 25, 27, 27, 27, 27,
- 27, 27, 27, 27, 29, 29, 29, 29, 29, 29, 29, 31, 31, 31, 31, 31,
- 31, 33, 33, 33, 33, 33, 36, 36, 36, 36, 38, 38, 38, 40, 40, 42, };
+ 6, 10, 10, 13, 11, 13, 16, 16, 16, 16, 18, 18, 18, 18, 18, 23,
+ 23, 23, 23, 23, 23, 25, 25, 25, 25, 25, 25, 25, 27, 27, 27, 27,
+ 27, 27, 27, 27, 29, 29, 29, 29, 29, 29, 29, 31, 31, 31, 31, 31,
+ 31, 33, 33, 33, 33, 33, 36, 36, 36, 36, 38, 38, 38, 40, 40, 42, };
static const int kDefault8x8Inter[kH264ScalingList8x8Length] = {
- 9, 13, 13, 15, 13, 15, 17, 17, 17, 17, 19, 19, 19, 19, 19, 21,
- 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 24, 24, 24, 24,
- 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 27, 27, 27, 27, 27,
- 27, 28, 28, 28, 28, 28, 30, 30, 30, 30, 32, 32, 32, 33, 33, 35, };
+ 9, 13, 13, 15, 13, 15, 17, 17, 17, 17, 19, 19, 19, 19, 19, 21,
+ 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 24, 24, 24, 24,
+ 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 27, 27, 27, 27, 27,
+ 27, 28, 28, 28, 28, 28, 30, 30, 30, 30, 32, 32, 32, 33, 33, 35, };
static inline void DefaultScalingList4x4(
int i,
@@ -335,8 +337,8 @@ static void FallbackScalingList4x4(
const int default_scaling_list_intra[],
const int default_scaling_list_inter[],
int scaling_list4x4[][kH264ScalingList4x4Length]) {
- static const int kScalingList4x4ByteSize = sizeof(scaling_list4x4[0][0]) *
- kH264ScalingList4x4Length;
+ static const int kScalingList4x4ByteSize =
+ sizeof(scaling_list4x4[0][0]) * kH264ScalingList4x4Length;
switch (i) {
case 0:
@@ -345,13 +347,11 @@ static void FallbackScalingList4x4(
break;
case 1:
- memcpy(scaling_list4x4[i], scaling_list4x4[0],
- kScalingList4x4ByteSize);
+ memcpy(scaling_list4x4[i], scaling_list4x4[0], kScalingList4x4ByteSize);
break;
case 2:
- memcpy(scaling_list4x4[i], scaling_list4x4[1],
- kScalingList4x4ByteSize);
+ memcpy(scaling_list4x4[i], scaling_list4x4[1], kScalingList4x4ByteSize);
break;
case 3:
@@ -360,13 +360,11 @@ static void FallbackScalingList4x4(
break;
case 4:
- memcpy(scaling_list4x4[i], scaling_list4x4[3],
- kScalingList4x4ByteSize);
+ memcpy(scaling_list4x4[i], scaling_list4x4[3], kScalingList4x4ByteSize);
break;
case 5:
- memcpy(scaling_list4x4[i], scaling_list4x4[4],
- kScalingList4x4ByteSize);
+ memcpy(scaling_list4x4[i], scaling_list4x4[4], kScalingList4x4ByteSize);
break;
default:
@@ -380,8 +378,8 @@ static void FallbackScalingList8x8(
const int default_scaling_list_intra[],
const int default_scaling_list_inter[],
int scaling_list8x8[][kH264ScalingList8x8Length]) {
- static const int kScalingList8x8ByteSize = sizeof(scaling_list8x8[0][0]) *
- kH264ScalingList8x8Length;
+ static const int kScalingList8x8ByteSize =
+ sizeof(scaling_list8x8[0][0]) * kH264ScalingList8x8Length;
switch (i) {
case 0:
@@ -395,23 +393,19 @@ static void FallbackScalingList8x8(
break;
case 2:
- memcpy(scaling_list8x8[i], scaling_list8x8[0],
- kScalingList8x8ByteSize);
+ memcpy(scaling_list8x8[i], scaling_list8x8[0], kScalingList8x8ByteSize);
break;
case 3:
- memcpy(scaling_list8x8[i], scaling_list8x8[1],
- kScalingList8x8ByteSize);
+ memcpy(scaling_list8x8[i], scaling_list8x8[1], kScalingList8x8ByteSize);
break;
case 4:
- memcpy(scaling_list8x8[i], scaling_list8x8[2],
- kScalingList8x8ByteSize);
+ memcpy(scaling_list8x8[i], scaling_list8x8[2], kScalingList8x8ByteSize);
break;
case 5:
- memcpy(scaling_list8x8[i], scaling_list8x8[3],
- kScalingList8x8ByteSize);
+ memcpy(scaling_list8x8[i], scaling_list8x8[3], kScalingList8x8ByteSize);
break;
default:
@@ -461,7 +455,8 @@ H264Parser::Result H264Parser::ParseSPSScalingLists(H264SPS* sps) {
if (seq_scaling_list_present_flag) {
res = ParseScalingList(arraysize(sps->scaling_list4x4[i]),
- sps->scaling_list4x4[i], &use_default);
+ sps->scaling_list4x4[i],
+ &use_default);
if (res != kOk)
return res;
@@ -469,8 +464,8 @@ H264Parser::Result H264Parser::ParseSPSScalingLists(H264SPS* sps) {
DefaultScalingList4x4(i, sps->scaling_list4x4);
} else {
- FallbackScalingList4x4(i, kDefault4x4Intra, kDefault4x4Inter,
- sps->scaling_list4x4);
+ FallbackScalingList4x4(
+ i, kDefault4x4Intra, kDefault4x4Inter, sps->scaling_list4x4);
}
}
@@ -480,7 +475,8 @@ H264Parser::Result H264Parser::ParseSPSScalingLists(H264SPS* sps) {
if (seq_scaling_list_present_flag) {
res = ParseScalingList(arraysize(sps->scaling_list8x8[i]),
- sps->scaling_list8x8[i], &use_default);
+ sps->scaling_list8x8[i],
+ &use_default);
if (res != kOk)
return res;
@@ -488,8 +484,8 @@ H264Parser::Result H264Parser::ParseSPSScalingLists(H264SPS* sps) {
DefaultScalingList8x8(i, sps->scaling_list8x8);
} else {
- FallbackScalingList8x8(i, kDefault8x8Intra, kDefault8x8Inter,
- sps->scaling_list8x8);
+ FallbackScalingList8x8(
+ i, kDefault8x8Intra, kDefault8x8Inter, sps->scaling_list8x8);
}
}
@@ -508,7 +504,8 @@ H264Parser::Result H264Parser::ParsePPSScalingLists(const H264SPS& sps,
if (pic_scaling_list_present_flag) {
res = ParseScalingList(arraysize(pps->scaling_list4x4[i]),
- pps->scaling_list4x4[i], &use_default);
+ pps->scaling_list4x4[i],
+ &use_default);
if (res != kOk)
return res;
@@ -518,12 +515,14 @@ H264Parser::Result H264Parser::ParsePPSScalingLists(const H264SPS& sps,
} else {
if (sps.seq_scaling_matrix_present_flag) {
// Table 7-2 fallback rule A in spec.
- FallbackScalingList4x4(i, kDefault4x4Intra, kDefault4x4Inter,
- pps->scaling_list4x4);
+ FallbackScalingList4x4(
+ i, kDefault4x4Intra, kDefault4x4Inter, pps->scaling_list4x4);
} else {
// Table 7-2 fallback rule B in spec.
- FallbackScalingList4x4(i, sps.scaling_list4x4[0],
- sps.scaling_list4x4[3], pps->scaling_list4x4);
+ FallbackScalingList4x4(i,
+ sps.scaling_list4x4[0],
+ sps.scaling_list4x4[3],
+ pps->scaling_list4x4);
}
}
}
@@ -534,7 +533,8 @@ H264Parser::Result H264Parser::ParsePPSScalingLists(const H264SPS& sps,
if (pic_scaling_list_present_flag) {
res = ParseScalingList(arraysize(pps->scaling_list8x8[i]),
- pps->scaling_list8x8[i], &use_default);
+ pps->scaling_list8x8[i],
+ &use_default);
if (res != kOk)
return res;
@@ -544,12 +544,14 @@ H264Parser::Result H264Parser::ParsePPSScalingLists(const H264SPS& sps,
} else {
if (sps.seq_scaling_matrix_present_flag) {
// Table 7-2 fallback rule A in spec.
- FallbackScalingList8x8(i, kDefault8x8Intra,
- kDefault8x8Inter, pps->scaling_list8x8);
+ FallbackScalingList8x8(
+ i, kDefault8x8Intra, kDefault8x8Inter, pps->scaling_list8x8);
} else {
// Table 7-2 fallback rule B in spec.
- FallbackScalingList8x8(i, sps.scaling_list8x8[0],
- sps.scaling_list8x8[1], pps->scaling_list8x8);
+ FallbackScalingList8x8(i,
+ sps.scaling_list8x8[0],
+ sps.scaling_list8x8[1],
+ pps->scaling_list8x8);
}
}
}
@@ -585,8 +587,8 @@ H264Parser::Result H264Parser::ParseSPS(int* sps_id) {
if (sps->profile_idc == 100 || sps->profile_idc == 110 ||
sps->profile_idc == 122 || sps->profile_idc == 244 ||
- sps->profile_idc == 44 || sps->profile_idc == 83 ||
- sps->profile_idc == 86 || sps->profile_idc == 118 ||
+ sps->profile_idc == 44 || sps->profile_idc == 83 ||
+ sps->profile_idc == 86 || sps->profile_idc == 118 ||
sps->profile_idc == 128) {
READ_UE_OR_RETURN(&sps->chroma_format_idc);
TRUE_OR_RETURN(sps->chroma_format_idc < 4);
@@ -897,7 +899,7 @@ H264Parser::Result H264Parser::ParsePredWeightTable(const H264SPS& sps,
return kOk;
}
-H264Parser::Result H264Parser::ParseDecRefPicMarking(H264SliceHeader *shdr) {
+H264Parser::Result H264Parser::ParseDecRefPicMarking(H264SliceHeader* shdr) {
if (shdr->idr_pic_flag) {
READ_BOOL_OR_RETURN(&shdr->no_output_of_prior_pics_flag);
READ_BOOL_OR_RETURN(&shdr->long_term_reference_flag);
@@ -973,8 +975,7 @@ H264Parser::Result H264Parser::ParseSliceHeader(const H264NALU& nalu,
return kUnsupportedStream;
}
- READ_BITS_OR_RETURN(sps->log2_max_frame_num_minus4 + 4,
- &shdr->frame_num);
+ READ_BITS_OR_RETURN(sps->log2_max_frame_num_minus4 + 4, &shdr->frame_num);
if (!sps->frame_mbs_only_flag) {
READ_BOOL_OR_RETURN(&shdr->field_pic_flag);
if (shdr->field_pic_flag) {
@@ -1053,8 +1054,8 @@ H264Parser::Result H264Parser::ParseSliceHeader(const H264NALU& nalu,
return res;
}
- if (pps->entropy_coding_mode_flag &&
- !shdr->IsISlice() && !shdr->IsSISlice()) {
+ if (pps->entropy_coding_mode_flag && !shdr->IsISlice() &&
+ !shdr->IsSISlice()) {
READ_UE_OR_RETURN(&shdr->cabac_init_idc);
TRUE_OR_RETURN(shdr->cabac_init_idc < 3);
}
@@ -1118,8 +1119,7 @@ H264Parser::Result H264Parser::ParseSEI(H264SEIMessage* sei_msg) {
READ_UE_OR_RETURN(&sei_msg->recovery_point.recovery_frame_cnt);
READ_BOOL_OR_RETURN(&sei_msg->recovery_point.exact_match_flag);
READ_BOOL_OR_RETURN(&sei_msg->recovery_point.broken_link_flag);
- READ_BITS_OR_RETURN(2,
- &sei_msg->recovery_point.changing_slice_group_idc);
+ READ_BITS_OR_RETURN(2, &sei_msg->recovery_point.changing_slice_group_idc);
break;
default:
@@ -1130,4 +1130,4 @@ H264Parser::Result H264Parser::ParseSEI(H264SEIMessage* sei_msg) {
return kOk;
}
-} // namespace content
+} // namespace media
diff --git a/content/common/gpu/media/h264_parser.h b/media/filters/h264_parser.h
index a4ab521..7f6eb3f 100644
--- a/content/common/gpu/media/h264_parser.h
+++ b/media/filters/h264_parser.h
@@ -1,25 +1,25 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This file contains an implementation of an H264 Annex-B video stream parser.
-#ifndef CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_
-#define CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_
+#ifndef MEDIA_FILTERS_H264_PARSER_H_
+#define MEDIA_FILTERS_H264_PARSER_H_
#include <sys/types.h>
#include <map>
#include "base/basictypes.h"
-#include "content/common/content_export.h"
-#include "content/common/gpu/media/h264_bit_reader.h"
+#include "media/base/media_export.h"
+#include "media/filters/h264_bit_reader.h"
-namespace content {
+namespace media {
// For explanations of each struct and its members, see H.264 specification
// at http://www.itu.int/rec/T-REC-H.264.
-struct CONTENT_EXPORT H264NALU {
+struct MEDIA_EXPORT H264NALU {
H264NALU();
enum Type {
@@ -43,9 +43,12 @@ struct CONTENT_EXPORT H264NALU {
int nal_unit_type;
};
-enum { kH264ScalingList4x4Length = 16, kH264ScalingList8x8Length = 64, };
+enum {
+ kH264ScalingList4x4Length = 16,
+ kH264ScalingList8x8Length = 64,
+};
-struct CONTENT_EXPORT H264SPS {
+struct MEDIA_EXPORT H264SPS {
H264SPS();
int profile_idc;
@@ -70,7 +73,7 @@ struct CONTENT_EXPORT H264SPS {
int offset_for_non_ref_pic;
int offset_for_top_to_bottom_field;
int num_ref_frames_in_pic_order_cnt_cycle;
- int expected_delta_per_pic_order_cnt_cycle; // calculated
+ int expected_delta_per_pic_order_cnt_cycle; // calculated
int offset_for_ref_frame[255];
int max_num_ref_frames;
bool gaps_in_frame_num_value_allowed_flag;
@@ -88,7 +91,7 @@ struct CONTENT_EXPORT H264SPS {
int chroma_array_type;
};
-struct CONTENT_EXPORT H264PPS {
+struct MEDIA_EXPORT H264PPS {
H264PPS();
int pic_parameter_set_id;
@@ -116,7 +119,7 @@ struct CONTENT_EXPORT H264PPS {
int second_chroma_qp_index_offset;
};
-struct CONTENT_EXPORT H264ModificationOfPicNum {
+struct MEDIA_EXPORT H264ModificationOfPicNum {
int modification_of_pic_nums_idc;
union {
int abs_diff_pic_num_minus1;
@@ -124,7 +127,7 @@ struct CONTENT_EXPORT H264ModificationOfPicNum {
};
};
-struct CONTENT_EXPORT H264WeightingFactors {
+struct MEDIA_EXPORT H264WeightingFactors {
bool luma_weight_flag;
bool chroma_weight_flag;
int luma_weight[32];
@@ -133,7 +136,7 @@ struct CONTENT_EXPORT H264WeightingFactors {
int chroma_offset[32][2];
};
-struct CONTENT_EXPORT H264DecRefPicMarking {
+struct MEDIA_EXPORT H264DecRefPicMarking {
int memory_mgmnt_control_operation;
int difference_of_pic_nums_minus1;
int long_term_pic_num;
@@ -141,7 +144,7 @@ struct CONTENT_EXPORT H264DecRefPicMarking {
int max_long_term_frame_idx_plus1;
};
-struct CONTENT_EXPORT H264SliceHeader {
+struct MEDIA_EXPORT H264SliceHeader {
H264SliceHeader();
enum {
@@ -163,11 +166,11 @@ struct CONTENT_EXPORT H264SliceHeader {
bool IsSPSlice() const;
bool IsSISlice() const;
- bool idr_pic_flag; // from NAL header
- int nal_ref_idc; // from NAL header
+ bool idr_pic_flag; // from NAL header
+ int nal_ref_idc; // from NAL header
const uint8* nalu_data; // from NAL header
- off_t nalu_size; // from NAL header
- off_t header_bit_size; // calculated
+ off_t nalu_size; // from NAL header
+ off_t header_bit_size; // calculated
int first_mb_in_slice;
int slice_type;
@@ -224,7 +227,7 @@ struct H264SEIRecoveryPoint {
int changing_slice_group_idc;
};
-struct CONTENT_EXPORT H264SEIMessage {
+struct MEDIA_EXPORT H264SEIMessage {
H264SEIMessage();
enum Type {
@@ -242,13 +245,13 @@ struct CONTENT_EXPORT H264SEIMessage {
// Class to parse an Annex-B H.264 stream,
// as specified in chapters 7 and Annex B of the H.264 spec.
-class CONTENT_EXPORT H264Parser {
+class MEDIA_EXPORT H264Parser {
public:
enum Result {
kOk,
- kInvalidStream, // error in stream
- kUnsupportedStream, // stream not supported by the parser
- kEOStream, // end of stream
+ kInvalidStream, // error in stream
+ kUnsupportedStream, // stream not supported by the parser
+ kEOStream, // end of stream
};
H264Parser();
@@ -331,7 +334,7 @@ class CONTENT_EXPORT H264Parser {
H264WeightingFactors* w_facts);
// Parse decoded reference picture marking information (see spec).
- Result ParseDecRefPicMarking(H264SliceHeader *shdr);
+ Result ParseDecRefPicMarking(H264SliceHeader* shdr);
// Pointer to the current NALU in the stream.
const uint8* stream_;
@@ -350,6 +353,6 @@ class CONTENT_EXPORT H264Parser {
DISALLOW_COPY_AND_ASSIGN(H264Parser);
};
-} // namespace content
+} // namespace media
-#endif // CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_
+#endif // MEDIA_FILTERS_H264_PARSER_H_
diff --git a/content/common/gpu/media/h264_parser_unittest.cc b/media/filters/h264_parser_unittest.cc
index d52bb51..a08cf26 100644
--- a/content/common/gpu/media/h264_parser_unittest.cc
+++ b/media/filters/h264_parser_unittest.cc
@@ -1,29 +1,26 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "testing/gtest/include/gtest/gtest.h"
-
#include "base/command_line.h"
#include "base/files/memory_mapped_file.h"
#include "base/logging.h"
+#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
-#include "content/common/gpu/media/h264_parser.h"
-
-using content::H264Parser;
-using content::H264NALU;
+#include "media/base/test_data_util.h"
+#include "media/filters/h264_parser.h"
+#include "testing/gtest/include/gtest/gtest.h"
-const base::FilePath::CharType* test_stream_filename =
- FILE_PATH_LITERAL("content/common/gpu/testdata/test-25fps.h264");
-// Number of NALUs in the stream to be parsed.
-int num_nalus = 759;
+namespace media {
TEST(H264ParserTest, StreamFileParsing) {
- base::FilePath fp(test_stream_filename);
+ base::FilePath file_path = GetTestDataFilePath("test-25fps.h264");
+ // Number of NALUs in the test stream to be parsed.
+ int num_nalus = 759;
+
base::MemoryMappedFile stream;
- CHECK(stream.Initialize(fp)) << "Couldn't open stream file: "
- << test_stream_filename;
- DVLOG(1) << "Parsing file: " << test_stream_filename;
+ ASSERT_TRUE(stream.Initialize(file_path))
+ << "Couldn't open stream file: " << file_path.MaybeAsASCII();
H264Parser parser;
parser.SetStream(stream.data(), stream.length());
@@ -31,8 +28,8 @@ TEST(H264ParserTest, StreamFileParsing) {
// Parse until the end of stream/unsupported stream/error in stream is found.
int num_parsed_nalus = 0;
while (true) {
- content::H264SliceHeader shdr;
- content::H264SEIMessage sei_msg;
+ media::H264SliceHeader shdr;
+ media::H264SEIMessage sei_msg;
H264NALU nalu;
H264Parser::Result res = parser.AdvanceToNextNALU(&nalu);
if (res == H264Parser::kEOStream) {
@@ -72,22 +69,4 @@ TEST(H264ParserTest, StreamFileParsing) {
}
}
-int main(int argc, char **argv) {
- ::testing::InitGoogleTest(&argc, argv);
- CommandLine::Init(argc, argv);
-
- const CommandLine::SwitchMap& switches =
- CommandLine::ForCurrentProcess()->GetSwitches();
- for (CommandLine::SwitchMap::const_iterator it = switches.begin();
- it != switches.end(); ++it) {
- if (it->first == "test_stream") {
- test_stream_filename = it->second.c_str();
- } else if (it->first == "num_nalus") {
- CHECK(base::StringToInt(it->second, &num_nalus));
- } else {
- LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second;
- }
- }
-
- return RUN_ALL_TESTS();
-}
+} // namespace media
diff --git a/media/media.gyp b/media/media.gyp
index e8b98a1..51d7cc0 100644
--- a/media/media.gyp
+++ b/media/media.gyp
@@ -385,6 +385,10 @@
'filters/gpu_video_accelerator_factories.h',
'filters/gpu_video_decoder.cc',
'filters/gpu_video_decoder.h',
+ 'filters/h264_bit_reader.cc',
+ 'filters/h264_bit_reader.h',
+ 'filters/h264_parser.cc',
+ 'filters/h264_parser.h',
'filters/h264_to_annex_b_bitstream_converter.cc',
'filters/h264_to_annex_b_bitstream_converter.h',
'filters/in_memory_url_protocol.cc',
@@ -1008,6 +1012,8 @@
'filters/ffmpeg_h264_to_annex_b_bitstream_converter_unittest.cc',
'filters/ffmpeg_video_decoder_unittest.cc',
'filters/file_data_source_unittest.cc',
+ 'filters/h264_bit_reader_unittest.cc',
+ 'filters/h264_parser_unittest.cc',
'filters/h264_to_annex_b_bitstream_converter_unittest.cc',
'filters/pipeline_integration_test.cc',
'filters/pipeline_integration_test_base.cc',