Skip to content

Commit

Permalink
Merge branch 'master' into pr-bitstream
Browse files Browse the repository at this point in the history
  • Loading branch information
dholroyd authored Jun 9, 2021
2 parents 7a02a3b + 7d47a96 commit a9ca4a4
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 19 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "h264-reader"
version = "0.5.0"
version = "0.5.1-dev"
authors = ["David Holroyd <[email protected]>"]
license = "MIT/Apache-2.0"
description = "Reader for H264 bitstream syntax"
Expand All @@ -14,6 +14,7 @@ edition = "2018"
bitstream-io = "1.0"
memchr = "2.1.1"
rfc6381-codec = "0.1"
log = "0.4"

[dev-dependencies]
hex-literal = "0.2.1"
Expand Down
9 changes: 5 additions & 4 deletions src/annexb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::Context;
use memchr;
use log::*;

#[derive(Debug)]
enum ParseState {
Expand Down Expand Up @@ -95,7 +96,7 @@ impl<R, Ctx> AnnexBReader<R, Ctx>
let b = buf[i];
match self.state {
ParseState::End => {
eprintln!("no previous call to start()");
error!("no previous call to start()");
self.state = ParseState::Error;
return;
},
Expand Down Expand Up @@ -214,7 +215,7 @@ impl<R, Ctx> AnnexBReader<R, Ctx>
self.to(ParseState::InUnitStart);
},
_ => {
eprintln!("Expected either start code byte 0x01 or end_units(), got byte {:#x}", b);
error!("Expected either start code byte 0x01 or end_units(), got byte {:#x}", b);
self.to(ParseState::Error);
},
}
Expand Down Expand Up @@ -273,12 +274,12 @@ impl<R, Ctx> AnnexBReader<R, Ctx>
};
self.nal_reader.push(ctx, &buf[start..end_index])
} else {
eprintln!("AnnexBReader: no start_index");
error!("AnnexBReader: no start_index");
}
}

fn err(&mut self, b: u8) {
eprintln!("AnnexBReader: state={:?}, invalid byte {:#x}", self.state, b);
error!("AnnexBReader: state={:?}, invalid byte {:#x}", self.state, b);
self.state = ParseState::Start;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/nal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::annexb::NalReader;
use std::cell::RefCell;
use crate::Context;
use std::fmt;
use log::*;

#[derive(PartialEq, Hash, Debug, Copy, Clone)]
pub enum UnitType {
Expand Down Expand Up @@ -210,7 +211,7 @@ impl<Ctx> NalReader for NalSwitch<Ctx> {
},
Err(e) => {
// TODO: proper error propagation
eprintln!("Bad NAL header: {:?}", e);
error!("Bad NAL header: {:?}", e);
NalSwitchState::Ignoring
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/nal/pps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::sps;
use std::marker;
use crate::{rbsp, Context};
use crate::rbsp::RbspBitReader;
use log::*;

#[derive(Debug)]
pub enum PpsError {
Expand Down Expand Up @@ -294,7 +295,7 @@ impl<Ctx> NalHandler for PicParameterSetNalHandler<Ctx> {
ctx.put_pic_param_set(pps);
},
Err(e) => {
eprintln!("pps: {:?}", e);
error!("pps: {:?}", e);
},
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/nal/sei/buffering_period.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::rbsp::RbspBitReader;
use crate::Context;
use crate::nal::sei::HeaderType;
use crate::rbsp::RbspBitReaderError;
use log::*;

#[derive(Debug)]
enum BufferingPeriodError {
Expand Down Expand Up @@ -94,9 +95,9 @@ impl<Ctx> SeiCompletePayloadReader for BufferingPeriodPayloadReader<Ctx> {
fn header(&mut self, ctx: &mut Context<Ctx>, payload_type: HeaderType, buf: &[u8]) {
assert_eq!(payload_type, HeaderType::BufferingPeriod);
match BufferingPeriod::read(ctx, buf) {
Err(e) => eprintln!("Failure reading buffering_period: {:?}", e),
Err(e) => error!("Failure reading buffering_period: {:?}", e),
Ok(buffering_period) => {
println!("buffering_period {:#?}", buffering_period);
info!("TODO: expose buffering_period {:#?}", buffering_period);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/nal/sei/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::Context;
use crate::nal::NalHandler;
use crate::nal::NalHeader;
use crate::rbsp::RbspDecoder;
use log::*;

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum HeaderType {
Expand Down Expand Up @@ -370,15 +371,15 @@ impl<R: SeiIncrementalPayloadReader> NalHandler for SeiHeaderReader<R> {
// be 0b10000000 in an SEI payload since SEI messages are byte-aligned).
},
SeiHeaderState::PayloadType { .. } => {
eprintln!("End of SEI data encountered while reading SEI payloadType");
error!("End of SEI data encountered while reading SEI payloadType");
self.reader.reset(ctx);
},
SeiHeaderState::PayloadSize { .. } => {
eprintln!("End of SEI data encountered while reading SEI payloadSize");
error!("End of SEI data encountered while reading SEI payloadSize");
self.reader.reset(ctx);
},
SeiHeaderState::Payload { payload_type, payload_size, consumed_size } => {
eprintln!("End of SEI data encountered having read {} bytes of payloadSize={} for header type {:?}", consumed_size, payload_size, payload_type);
error!("End of SEI data encountered having read {} bytes of payloadSize={} for header type {:?}", consumed_size, payload_size, payload_type);
self.reader.reset(ctx);
},
}
Expand Down
3 changes: 2 additions & 1 deletion src/nal/sei/pic_timing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::nal::pps::ParamSetId;
use crate::rbsp::RbspBitReader;
use crate::nal::sps;
use crate::rbsp::RbspBitReaderError;
use log::*;

// FIXME: SPS selection
// We should really wait until we know what SPS is in use by the frame which follows the
Expand Down Expand Up @@ -324,7 +325,7 @@ impl<H: PicTimingHandler> SeiCompletePayloadReader for PicTimingReader<H> {
fn header(&mut self, ctx: &mut Context<Self::Ctx>, payload_type: HeaderType, buf: &[u8]) {
assert_eq!(payload_type, HeaderType::PicTiming);
match PicTiming::read(ctx, buf) {
Err(e) => eprintln!("Failure reading pic_timing: {:?}", e),
Err(e) => error!("Failure reading pic_timing: {:?}", e),
Ok(pic_timing) => {
self.handler.handle(ctx, pic_timing);
}
Expand Down
3 changes: 2 additions & 1 deletion src/nal/sei/user_data_registered_itu_t_t35.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::nal::sei::HeaderType;
use crate::Context;
use crate::nal::sei::SeiCompletePayloadReader;
use log::*;

#[derive(Debug)]
pub enum ItuTT35Error {
Expand Down Expand Up @@ -447,7 +448,7 @@ impl<R: Register> SeiCompletePayloadReader for UserDataRegisteredItuTT35Reader<R
self.register.handle(ctx, country_code, payload);
},
Err(e) => {
eprintln!("Failed to read user_data_registered_itu_t_t35 header: {:?}", e);
error!("Failed to read user_data_registered_itu_t_t35 header: {:?}", e);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/nal/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::nal::sps;
use std::marker;
use crate::nal::sps::SeqParameterSet;
use crate::nal::NalHeader;
use log::*;

enum ParseState {
Unstarted,
Expand Down Expand Up @@ -535,7 +536,6 @@ impl<Ctx> super::NalHandler for SliceLayerWithoutPartitioningRbsp<Ctx> {
type Ctx = Ctx;

fn start(&mut self, _ctx: &mut Context<Ctx>, header: NalHeader) {
println!("SliceLayerWithoutPartitioningRbsp: start()");
self.state = ParseState::Start(header);
}

Expand All @@ -545,8 +545,8 @@ impl<Ctx> super::NalHandler for SliceLayerWithoutPartitioningRbsp<Ctx> {
ParseState::Start(header) => {
let mut r = RbspBitReader::new(buf);
match SliceHeader::read(ctx, &mut r, header) {
Ok(header) => println!("{:#?}", header),
Err(e) => println!("slice_header() error: SliceHeaderError::{:?}", e),
Ok(header) => info!("TODO: expose to caller: {:#?}", header),
Err(e) => error!("slice_header() error: SliceHeaderError::{:?}", e),
}
self.state = ParseState::Continue(header);
},
Expand All @@ -557,7 +557,7 @@ impl<Ctx> super::NalHandler for SliceLayerWithoutPartitioningRbsp<Ctx> {
}

fn end(&mut self, _ctx: &mut Context<Ctx>) {
println!("SliceLayerWithoutPartitioningRbsp: end()");
// TODO
}
}
impl<Ctx> Default for SliceLayerWithoutPartitioningRbsp<Ctx> {
Expand Down
3 changes: 2 additions & 1 deletion src/rbsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use bitstream_io::read::BitRead;
use std::borrow::Cow;
use crate::nal::{NalHandler, NalHeader};
use crate::Context;
use log::*;

#[derive(Debug)]
enum ParseState {
Expand Down Expand Up @@ -75,7 +76,7 @@ impl<R> RbspDecoder<R>
if let Some(start) = start_index {
self.nal_reader.push(ctx, &buf[start..end_index])
} else {
eprintln!("RbspDecoder: no start_index");
error!("RbspDecoder: no start_index");
}
}

Expand Down

0 comments on commit a9ca4a4

Please sign in to comment.