mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2024-12-26 07:05:56 -05:00
address AVStream::codec deprecation
The codec -> codecpar move was sufficiently long ago (libavformat 57.5.0 on 2016-04-11) that I think we can just get away with requiring the new version. Let's try it. But if someone complains, AVCodecParameters and AVCodecContext look sufficiently similar we could probably just use one or the other based on the version we're compiling with.
This commit is contained in:
parent
7179ea04e3
commit
6fb346cc8b
@ -32,7 +32,7 @@ fn main() {
|
||||
let libraries = [
|
||||
pkg_config::Config::new().atleast_version("54.1").probe("libavutil").unwrap(),
|
||||
pkg_config::Config::new().atleast_version("56.0").probe("libavcodec").unwrap(),
|
||||
pkg_config::Config::new().atleast_version("56.0").probe("libavformat").unwrap(),
|
||||
pkg_config::Config::new().atleast_version("57.5").probe("libavformat").unwrap(),
|
||||
];
|
||||
let mut wrapper = cc::Build::new();
|
||||
|
||||
|
@ -43,11 +43,11 @@ extern "C" {
|
||||
fn av_init_packet(p: *mut AVPacket);
|
||||
fn av_packet_unref(p: *mut AVPacket);
|
||||
|
||||
fn moonfire_ffmpeg_cctx_codec_id(ctx: *const AVCodecContext) -> libc::c_int;
|
||||
fn moonfire_ffmpeg_cctx_codec_type(ctx: *const AVCodecContext) -> libc::c_int;
|
||||
fn moonfire_ffmpeg_cctx_extradata(ctx: *const AVCodecContext) -> DataLen;
|
||||
fn moonfire_ffmpeg_cctx_height(ctx: *const AVCodecContext) -> libc::c_int;
|
||||
fn moonfire_ffmpeg_cctx_width(ctx: *const AVCodecContext) -> libc::c_int;
|
||||
fn moonfire_ffmpeg_codecpar_codec_id(ctx: *const AVCodecParameters) -> libc::c_int;
|
||||
fn moonfire_ffmpeg_codecpar_codec_type(ctx: *const AVCodecParameters) -> libc::c_int;
|
||||
fn moonfire_ffmpeg_codecpar_extradata(ctx: *const AVCodecParameters) -> DataLen;
|
||||
fn moonfire_ffmpeg_codecpar_height(ctx: *const AVCodecParameters) -> libc::c_int;
|
||||
fn moonfire_ffmpeg_codecpar_width(ctx: *const AVCodecParameters) -> libc::c_int;
|
||||
}
|
||||
|
||||
//#[link(name = "avformat")]
|
||||
@ -66,7 +66,7 @@ extern "C" {
|
||||
|
||||
fn moonfire_ffmpeg_fctx_streams(ctx: *const AVFormatContext) -> StreamsLen;
|
||||
|
||||
fn moonfire_ffmpeg_stream_codec(stream: *const AVStream) -> *const AVCodecContext;
|
||||
fn moonfire_ffmpeg_stream_codecpar(stream: *const AVStream) -> *const AVCodecParameters;
|
||||
fn moonfire_ffmpeg_stream_time_base(stream: *const AVStream) -> AVRational;
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ pub struct AVRational {
|
||||
}
|
||||
|
||||
// No ABI stability assumption here; use heap allocation/deallocation and accessors only.
|
||||
enum AVCodecContext {}
|
||||
enum AVCodecParameters {}
|
||||
enum AVDictionary {}
|
||||
enum AVFormatContext {}
|
||||
enum AVInputFormat {}
|
||||
@ -259,8 +259,8 @@ impl<'owner> Streams<'owner> {
|
||||
pub struct Stream<'o>(&'o AVStream);
|
||||
|
||||
impl<'o> Stream<'o> {
|
||||
pub fn codec<'s>(&'s self) -> CodecContext<'s> {
|
||||
CodecContext(unsafe { moonfire_ffmpeg_stream_codec(self.0).as_ref() }.unwrap())
|
||||
pub fn codecpar<'s>(&'s self) -> CodecParameters<'s> {
|
||||
CodecParameters(unsafe { moonfire_ffmpeg_stream_codecpar(self.0).as_ref() }.unwrap())
|
||||
}
|
||||
|
||||
pub fn time_base(&self) -> AVRational {
|
||||
@ -268,22 +268,22 @@ impl<'o> Stream<'o> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CodecContext<'s>(&'s AVCodecContext);
|
||||
pub struct CodecParameters<'s>(&'s AVCodecParameters);
|
||||
|
||||
impl<'s> CodecContext<'s> {
|
||||
impl<'s> CodecParameters<'s> {
|
||||
pub fn extradata(&self) -> &[u8] {
|
||||
unsafe {
|
||||
let d = moonfire_ffmpeg_cctx_extradata(self.0);
|
||||
let d = moonfire_ffmpeg_codecpar_extradata(self.0);
|
||||
::std::slice::from_raw_parts(d.data, d.len)
|
||||
}
|
||||
}
|
||||
pub fn width(&self) -> libc::c_int { unsafe { moonfire_ffmpeg_cctx_width(self.0) } }
|
||||
pub fn height(&self) -> libc::c_int { unsafe { moonfire_ffmpeg_cctx_height(self.0) } }
|
||||
pub fn width(&self) -> libc::c_int { unsafe { moonfire_ffmpeg_codecpar_width(self.0) } }
|
||||
pub fn height(&self) -> libc::c_int { unsafe { moonfire_ffmpeg_codecpar_height(self.0) } }
|
||||
pub fn codec_id(&self) -> CodecId {
|
||||
CodecId(unsafe { moonfire_ffmpeg_cctx_codec_id(self.0) })
|
||||
CodecId(unsafe { moonfire_ffmpeg_codecpar_codec_id(self.0) })
|
||||
}
|
||||
pub fn codec_type(&self) -> MediaType {
|
||||
MediaType(unsafe { moonfire_ffmpeg_cctx_codec_type(self.0) })
|
||||
MediaType(unsafe { moonfire_ffmpeg_codecpar_codec_type(self.0) })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,14 +136,16 @@ struct moonfire_ffmpeg_data moonfire_ffmpeg_packet_data(AVPacket *pkt) {
|
||||
return d;
|
||||
}
|
||||
|
||||
AVCodecContext *moonfire_ffmpeg_stream_codec(AVStream *stream) { return stream->codec; }
|
||||
AVCodecParameters *moonfire_ffmpeg_stream_codecpar(AVStream *stream) { return stream->codecpar; }
|
||||
AVRational moonfire_ffmpeg_stream_time_base(AVStream *stream) { return stream->time_base; }
|
||||
|
||||
int moonfire_ffmpeg_cctx_codec_id(AVCodecContext *cctx) { return cctx->codec_id; }
|
||||
int moonfire_ffmpeg_cctx_codec_type(AVCodecContext *cctx) { return cctx->codec_type; }
|
||||
struct moonfire_ffmpeg_data moonfire_ffmpeg_cctx_extradata(AVCodecContext *cctx) {
|
||||
struct moonfire_ffmpeg_data d = {cctx->extradata, cctx->extradata_size};
|
||||
int moonfire_ffmpeg_codecpar_codec_id(AVCodecParameters *codecpar) { return codecpar->codec_id; }
|
||||
int moonfire_ffmpeg_codecpar_codec_type(AVCodecParameters *codecpar) {
|
||||
return codecpar->codec_type;
|
||||
}
|
||||
struct moonfire_ffmpeg_data moonfire_ffmpeg_codecpar_extradata(AVCodecParameters *codecpar) {
|
||||
struct moonfire_ffmpeg_data d = {codecpar->extradata, codecpar->extradata_size};
|
||||
return d;
|
||||
}
|
||||
int moonfire_ffmpeg_cctx_height(AVCodecContext *cctx) { return cctx->height; }
|
||||
int moonfire_ffmpeg_cctx_width(AVCodecContext *cctx) { return cctx->width; }
|
||||
int moonfire_ffmpeg_codecpar_height(AVCodecParameters *codecpar) { return codecpar->height; }
|
||||
int moonfire_ffmpeg_codecpar_width(AVCodecParameters *codecpar) { return codecpar->width; }
|
||||
|
@ -123,7 +123,7 @@ impl Opener<FfmpegStream> for Ffmpeg {
|
||||
{
|
||||
let s = input.streams();
|
||||
for i in 0 .. s.len() {
|
||||
if s.get(i).codec().codec_type().is_video() {
|
||||
if s.get(i).codecpar().codec_type().is_video() {
|
||||
debug!("Video stream index is {}", i);
|
||||
video_i = Some(i);
|
||||
break;
|
||||
@ -161,7 +161,7 @@ impl Stream for FfmpegStream {
|
||||
if tb.num != 1 || tb.den != 90000 {
|
||||
bail!("video stream has timebase {}/{}; expected 1/90000", tb.num, tb.den);
|
||||
}
|
||||
let codec = video.codec();
|
||||
let codec = video.codecpar();
|
||||
let codec_id = codec.codec_id();
|
||||
if !codec_id.is_h264() {
|
||||
bail!("stream's video codec {:?} is not h264", codec_id);
|
||||
|
Loading…
Reference in New Issue
Block a user