Skip to content

Commit

Permalink
Bump rusty_ffmpeg to 0.14 (#173)
Browse files Browse the repository at this point in the history
* Update rusty_ffmpeg to 0.14

* Migrate to new rusty_ffmpeg enum usage
  • Loading branch information
ldm0 authored Apr 5, 2024
1 parent 643dd97 commit 65e414e
Show file tree
Hide file tree
Showing 19 changed files with 142 additions and 151 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exclude = ["tests/*", "examples/*", "utils/*"]
rust-version = "1.70.0"

[dependencies]
rusty_ffmpeg = { version = "0.13.3", features = ["ffmpeg6"] }
rusty_ffmpeg = "0.14.0"
libc = "0.2"
paste = "1.0"
thiserror = "1.0"
Expand All @@ -29,3 +29,4 @@ camino = "1.1.6"
[features]
# linking system ffmpeg as fallback.
link_system_ffmpeg = ["rusty_ffmpeg/link_system_ffmpeg"]
ffmpeg6 = ["rusty_ffmpeg/ffmpeg6"]
4 changes: 2 additions & 2 deletions src/avutil/channel_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl AVChannelLayout {
/// Return `None` if idx is not valid or the channel order is unspecified
pub fn channel_from_index(&self, idx: u32) -> Option<ffi::AVChannel> {
let channel = unsafe { ffi::av_channel_layout_channel_from_index(self.as_ptr(), idx) };
(channel != ffi::AVChannel_AV_CHAN_NONE).then_some(channel)
(channel != ffi::AV_CHAN_NONE).then_some(channel)
}

/// Get the index of a given channel in a channel layout. In case multiple
Expand All @@ -159,7 +159,7 @@ impl AVChannelLayout {
pub fn channel_from_string(&self, name: &CStr) -> Option<ffi::AVChannel> {
let channel =
unsafe { ffi::av_channel_layout_channel_from_string(self.as_ptr(), name.as_ptr()) };
(channel != ffi::AVChannel_AV_CHAN_NONE).then_some(channel)
(channel != ffi::AV_CHAN_NONE).then_some(channel)
}

/// Find out what channels from a given set are present in a channel layout,
Expand Down
6 changes: 3 additions & 3 deletions src/avutil/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ mod test {

#[test]
fn test_get_buffer() {
let encoder = AVCodec::find_encoder(ffi::AVCodecID_AV_CODEC_ID_AAC).unwrap();
let encoder = AVCodec::find_encoder(ffi::AV_CODEC_ID_AAC).unwrap();
let mut frame = AVFrame::new();
frame.set_nb_samples(2);
frame.set_ch_layout(AVChannelLayout::from_nb_channels(2).into_inner());
Expand All @@ -304,7 +304,7 @@ mod test {

#[test]
fn test_get_buffer_double_alloc() {
let encoder = AVCodec::find_encoder(ffi::AVCodecID_AV_CODEC_ID_AAC).unwrap();
let encoder = AVCodec::find_encoder(ffi::AV_CODEC_ID_AAC).unwrap();
let mut frame = AVFrame::new();
frame.set_nb_samples(2);
frame.set_ch_layout(AVChannelLayout::from_nb_channels(2).into_inner());
Expand All @@ -318,7 +318,7 @@ mod test {

#[test]
fn test_frame_with_image_buffer() {
let image = AVImage::new(ffi::AVPixelFormat_AV_PIX_FMT_RGB24, 256, 256, 0).unwrap();
let image = AVImage::new(ffi::AV_PIX_FMT_RGB24, 256, 256, 0).unwrap();
let frame = AVFrameWithImage::new(image);
let _: &Vec<u8> = &frame.image;
}
Expand Down
2 changes: 1 addition & 1 deletion src/avutil/imgutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ wrap! {
linesizes: [i32; AV_NUM_DATA_POINTERS] = [0; AV_NUM_DATA_POINTERS],
width: i32 = 0,
height: i32 = 0,
pix_fmt: AVPixelFormat = ffi::AVPixelFormat_AV_PIX_FMT_NONE,
pix_fmt: AVPixelFormat = ffi::AV_PIX_FMT_NONE,
}

impl AVImage {
Expand Down
10 changes: 5 additions & 5 deletions src/avutil/media_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ pub struct AVMediaType(pub ffi::AVMediaType);
impl AVMediaType {
/// A video codec
pub fn is_video(&self) -> bool {
self.0 == ffi::AVMediaType_AVMEDIA_TYPE_VIDEO
self.0 == ffi::AVMEDIA_TYPE_VIDEO
}

/// An audio codec
pub fn is_audio(&self) -> bool {
self.0 == ffi::AVMediaType_AVMEDIA_TYPE_AUDIO
self.0 == ffi::AVMEDIA_TYPE_AUDIO
}

/// A data codec(Opaque data information usually continuous)
pub fn is_data(&self) -> bool {
self.0 == ffi::AVMediaType_AVMEDIA_TYPE_DATA
self.0 == ffi::AVMEDIA_TYPE_DATA
}

/// A subtitle codec
pub fn is_subtitle(&self) -> bool {
self.0 == ffi::AVMediaType_AVMEDIA_TYPE_SUBTITLE
self.0 == ffi::AVMEDIA_TYPE_SUBTITLE
}

/// An attachment codec(Opaque data information usually sparse)
pub fn is_attachment(&self) -> bool {
self.0 == ffi::AVMediaType_AVMEDIA_TYPE_ATTACHMENT
self.0 == ffi::AVMEDIA_TYPE_ATTACHMENT
}
}
15 changes: 6 additions & 9 deletions src/avutil/pixdesc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl AVPixFmtDescriptorRef {

/// Iterate over all pixel format descriptors known to libavutil.
///
/// You can started with [`ffi::AVPixelFormat_AV_PIX_FMT_YUV420P`]
/// You can started with [`ffi::AV_PIX_FMT_YUV420P`]
///
/// Return next descriptor or None after the last descriptor
pub fn next(&self) -> Option<Self> {
Expand All @@ -37,7 +37,7 @@ impl AVPixFmtDescriptorRef {
}

/// Return an AVPixelFormat id described by desc, or
/// [`ffi::AVPixelFormat_AV_PIX_FMT_NONE`] if desc is not a valid pointer to
/// [`ffi::AV_PIX_FMT_NONE`] if desc is not a valid pointer to
/// a pixel format descriptor.
pub fn get_id(&self) -> i32 {
unsafe { ffi::av_pix_fmt_desc_get_id(self.0.as_ptr()) }
Expand All @@ -64,8 +64,7 @@ mod tests {
use cstr::cstr;
#[test]
fn test_pix_fmt_getter() {
let pix_fmt_desc =
AVPixFmtDescriptorRef::get(ffi::AVPixelFormat_AV_PIX_FMT_YUV420P).unwrap();
let pix_fmt_desc = AVPixFmtDescriptorRef::get(ffi::AV_PIX_FMT_YUV420P).unwrap();
assert_eq!(pix_fmt_desc.name(), cstr!("yuv420p"));
assert_eq!(pix_fmt_desc.alias(), None);

Expand All @@ -89,16 +88,14 @@ mod tests {
assert_eq!(pix_fmt_desc.comp[1].depth, 8);
assert_eq!(pix_fmt_desc.comp[2].depth, 8);

let pix_fmt_desc =
AVPixFmtDescriptorRef::get(ffi::AVPixelFormat_AV_PIX_FMT_GRAY9LE).unwrap();
let pix_fmt_desc = AVPixFmtDescriptorRef::get(ffi::AV_PIX_FMT_GRAY9LE).unwrap();
assert_eq!(pix_fmt_desc.name(), cstr!("gray9le"));
assert_eq!(pix_fmt_desc.alias(), Some(cstr!("y9le")));
}

#[test]
fn test_pix_fmt_desc_next() {
let pix_fmt_desc =
AVPixFmtDescriptorRef::get(ffi::AVPixelFormat_AV_PIX_FMT_GRAYF32BE).unwrap();
let pix_fmt_desc = AVPixFmtDescriptorRef::get(ffi::AV_PIX_FMT_GRAYF32BE).unwrap();
assert_eq!(pix_fmt_desc.name(), cstr!("grayf32be"));
assert_eq!(pix_fmt_desc.alias(), Some(cstr!("yf32be")));

Expand All @@ -109,7 +106,7 @@ mod tests {

#[test]
fn test_pix_fmt_get_id() {
let pix_fmt = ffi::AVPixelFormat_AV_PIX_FMT_YUVA444P12LE;
let pix_fmt = ffi::AV_PIX_FMT_YUVA444P12LE;
let pix_fmt_desc = AVPixFmtDescriptorRef::get(pix_fmt).unwrap();
assert_eq!(pix_fmt_desc.get_id(), pix_fmt);
}
Expand Down
32 changes: 16 additions & 16 deletions src/avutil/samplefmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ pub type AVSampleFormat = ffi::AVSampleFormat;
///
/// ```rust
/// # use rsmpeg::avutil::get_sample_fmt_name;
/// # use rsmpeg::ffi::AVSampleFormat_AV_SAMPLE_FMT_FLT;
/// # use rsmpeg::ffi::AV_SAMPLE_FMT_FLT;
/// # use std::ffi::CString;
/// # fn main() {
/// assert_eq!(
/// CString::new("flt").ok().as_deref(),
/// get_sample_fmt_name(AVSampleFormat_AV_SAMPLE_FMT_FLT)
/// get_sample_fmt_name(AV_SAMPLE_FMT_FLT)
/// );
/// # }
/// ```
Expand All @@ -33,63 +33,63 @@ pub fn get_sample_fmt_name(sample_fmt: AVSampleFormat) -> Option<&'static CStr>
///
/// ```rust
/// # use rsmpeg::avutil::get_sample_fmt;
/// # use rsmpeg::ffi::AVSampleFormat_AV_SAMPLE_FMT_FLT;
/// # use rsmpeg::ffi::AV_SAMPLE_FMT_FLT;
/// # use std::ffi::CString;
/// # fn main() {
/// assert_eq!(
/// Some(AVSampleFormat_AV_SAMPLE_FMT_FLT),
/// Some(AV_SAMPLE_FMT_FLT),
/// get_sample_fmt(&CString::new("flt").unwrap())
/// );
/// # }
/// ```
pub fn get_sample_fmt(name: &CStr) -> Option<AVSampleFormat> {
let sample_fmt = unsafe { ffi::av_get_sample_fmt(name.as_ptr()) };
match sample_fmt {
ffi::AVSampleFormat_AV_SAMPLE_FMT_NONE => None,
ffi::AV_SAMPLE_FMT_NONE => None,
_ => Some(sample_fmt),
}
}

/// Get the packed alternative form of the given sample format, return `None` on
/// error.
///
/// i.e. [`AV_SAMPLE_FMT_S16P`](ffi::AVSampleFormat_AV_SAMPLE_FMT_S16P) => [`AV_SAMPLE_FMT_S16`](ffi::AVSampleFormat_AV_SAMPLE_FMT_S16)
/// i.e. [`AV_SAMPLE_FMT_S16P`](ffi::AV_SAMPLE_FMT_S16P) => [`AV_SAMPLE_FMT_S16`](ffi::AV_SAMPLE_FMT_S16)
/// ```rust
/// # use rsmpeg::avutil::get_packed_sample_fmt;
/// # use rsmpeg::ffi::{AVSampleFormat_AV_SAMPLE_FMT_S16, AVSampleFormat_AV_SAMPLE_FMT_S16P};
/// # use rsmpeg::ffi::{AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P};
/// # fn main() {
/// assert_eq!(
/// Some(AVSampleFormat_AV_SAMPLE_FMT_S16),
/// get_packed_sample_fmt(AVSampleFormat_AV_SAMPLE_FMT_S16P)
/// Some(AV_SAMPLE_FMT_S16),
/// get_packed_sample_fmt(AV_SAMPLE_FMT_S16P)
/// );
/// # }
/// ```
pub fn get_packed_sample_fmt(sample_fmt: AVSampleFormat) -> Option<AVSampleFormat> {
let sample_fmt = unsafe { ffi::av_get_packed_sample_fmt(sample_fmt) };
match sample_fmt {
ffi::AVSampleFormat_AV_SAMPLE_FMT_NONE => None,
ffi::AV_SAMPLE_FMT_NONE => None,
_ => Some(sample_fmt),
}
}

/// Get the planar alternative form of the given sample format. return `None` on
/// error.
///
/// i.e. [`AV_SAMPLE_FMT_S16`](ffi::AVSampleFormat_AV_SAMPLE_FMT_S16) => [`AV_SAMPLE_FMT_S16P`](ffi::AVSampleFormat_AV_SAMPLE_FMT_S16P)
/// i.e. [`AV_SAMPLE_FMT_S16`](ffi::AV_SAMPLE_FMT_S16) => [`AV_SAMPLE_FMT_S16P`](ffi::AV_SAMPLE_FMT_S16P)
/// ```rust
/// # use rsmpeg::avutil::get_planar_sample_fmt;
/// # use rsmpeg::ffi::{AVSampleFormat_AV_SAMPLE_FMT_S16, AVSampleFormat_AV_SAMPLE_FMT_S16P};
/// # use rsmpeg::ffi::{AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P};
/// # fn main() {
/// assert_eq!(
/// Some(AVSampleFormat_AV_SAMPLE_FMT_S16P),
/// get_planar_sample_fmt(AVSampleFormat_AV_SAMPLE_FMT_S16)
/// Some(AV_SAMPLE_FMT_S16P),
/// get_planar_sample_fmt(AV_SAMPLE_FMT_S16)
/// );
/// # }
/// ```
pub fn get_planar_sample_fmt(sample_fmt: AVSampleFormat) -> Option<AVSampleFormat> {
let sample_fmt = unsafe { ffi::av_get_planar_sample_fmt(sample_fmt) };
match sample_fmt {
ffi::AVSampleFormat_AV_SAMPLE_FMT_NONE => None,
ffi::AV_SAMPLE_FMT_NONE => None,
_ => Some(sample_fmt),
}
}
Expand Down Expand Up @@ -127,7 +127,7 @@ wrap! {
linesize: i32 = 0,
nb_channels: i32 = 0,
nb_samples: i32 = 0,
sample_fmt: AVSampleFormat = ffi::AVSampleFormat_AV_SAMPLE_FMT_NONE,
sample_fmt: AVSampleFormat = ffi::AV_SAMPLE_FMT_NONE,
align: i32 = 0,
}

Expand Down
12 changes: 5 additions & 7 deletions src/swscale/swscale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,17 @@ impl Drop for SwsContext {
#[cfg(test)]
mod tests {
use super::*;
use crate::ffi::{
AVPixelFormat_AV_PIX_FMT_RGB24, SWS_BICUBIC, SWS_FULL_CHR_H_INT, SWS_PARAM_DEFAULT,
};
use crate::ffi::{AV_PIX_FMT_RGB24, SWS_BICUBIC, SWS_FULL_CHR_H_INT, SWS_PARAM_DEFAULT};

#[test]
fn test_cached_sws_context() {
let context = SwsContext::get_context(
10,
10,
AVPixelFormat_AV_PIX_FMT_RGB24,
AV_PIX_FMT_RGB24,
10,
10,
AVPixelFormat_AV_PIX_FMT_RGB24,
AV_PIX_FMT_RGB24,
SWS_FULL_CHR_H_INT | SWS_BICUBIC,
None,
None,
Expand All @@ -189,10 +187,10 @@ mod tests {
.get_cached_context(
10,
10,
AVPixelFormat_AV_PIX_FMT_RGB24,
AV_PIX_FMT_RGB24,
10,
10,
AVPixelFormat_AV_PIX_FMT_RGB24,
AV_PIX_FMT_RGB24,
SWS_FULL_CHR_H_INT | SWS_BICUBIC,
None,
None,
Expand Down
12 changes: 6 additions & 6 deletions tests/ffmpeg_examples/decode_audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ use std::{

fn get_format_from_sample_fmt(sample_fmt: AVSampleFormat) -> Option<&'static str> {
let sample_fmt_entries = [
(ffi::AVSampleFormat_AV_SAMPLE_FMT_U8, "u8"),
(ffi::AVSampleFormat_AV_SAMPLE_FMT_S16, "s16le"),
(ffi::AVSampleFormat_AV_SAMPLE_FMT_S32, "s32le"),
(ffi::AVSampleFormat_AV_SAMPLE_FMT_FLT, "f32le"),
(ffi::AVSampleFormat_AV_SAMPLE_FMT_DBL, "f64le"),
(ffi::AV_SAMPLE_FMT_U8, "u8"),
(ffi::AV_SAMPLE_FMT_S16, "s16le"),
(ffi::AV_SAMPLE_FMT_S32, "s32le"),
(ffi::AV_SAMPLE_FMT_FLT, "f32le"),
(ffi::AV_SAMPLE_FMT_DBL, "f64le"),
];
sample_fmt_entries
.iter()
Expand Down Expand Up @@ -80,7 +80,7 @@ fn decode_audio(audio_path: &str, out_file_path: &str) -> Result<()> {
let mut input_format_context = AVFormatContextInput::open(&audio_path, None, &mut None)
.context("Open audio file failed.")?;
let (stream_index, decoder) = input_format_context
.find_best_stream(ffi::AVMediaType_AVMEDIA_TYPE_AUDIO)
.find_best_stream(ffi::AVMEDIA_TYPE_AUDIO)
.context("Find best stream failed.")?
.context("Cannot find audio stream in this file.")?;
let mut decode_context = AVCodecContext::new(&decoder);
Expand Down
3 changes: 1 addition & 2 deletions tests/ffmpeg_examples/decode_video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ fn decode_video(video_path: &str, out_dir: &str) -> Result<()> {
// set end of buffer to 0 (this ensures that no overreading happens for damaged MPEG streams)
let mut inbuf = vec![0u8; INBUF_SIZE + AV_INPUT_BUFFER_PADDING_SIZE as usize];

let decoder =
AVCodec::find_decoder(ffi::AVCodecID_AV_CODEC_ID_MPEG1VIDEO).context("Codec not found")?;
let decoder = AVCodec::find_decoder(ffi::AV_CODEC_ID_MPEG1VIDEO).context("Codec not found")?;
let mut decode_context = AVCodecContext::new(&decoder);
decode_context.open(None).context("Could not open codec")?;

Expand Down
4 changes: 2 additions & 2 deletions tests/ffmpeg_examples/encode_video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ fn encode_video(codec_name: &CStr, file_name: &str) -> Result<()> {
encode_context.set_framerate(ra(25, 1));
encode_context.set_gop_size(10);
encode_context.set_max_b_frames(1);
encode_context.set_pix_fmt(ffi::AVPixelFormat_AV_PIX_FMT_YUV420P);
if encoder.id == ffi::AVCodecID_AV_CODEC_ID_H264 {
encode_context.set_pix_fmt(ffi::AV_PIX_FMT_YUV420P);
if encoder.id == ffi::AV_CODEC_ID_H264 {
unsafe { opt_set(encode_context.priv_data, cstr!("preset"), cstr!("slow"), 0) }
.context("Set preset failed.")?;
}
Expand Down
6 changes: 2 additions & 4 deletions tests/ffmpeg_examples/extract_mvs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ fn decode_packet(

*video_frame_count += 1;

if let Some(side_data) =
frame.get_side_data(ffi::AVFrameSideDataType_AV_FRAME_DATA_MOTION_VECTORS)
{
if let Some(side_data) = frame.get_side_data(ffi::AV_FRAME_DATA_MOTION_VECTORS) {
let raw_motion_vectors = unsafe { side_data.as_motion_vectors() };
for &motion_vector in raw_motion_vectors {
println!(
Expand All @@ -57,7 +55,7 @@ fn decode_packet(
/// Extract motion vectors from a video.
fn extract_mvs(video_path: &CStr) -> Result<()> {
let mut input_format_context = AVFormatContextInput::open(video_path, None, &mut None)?;
let media_type = ffi::AVMediaType_AVMEDIA_TYPE_VIDEO;
let media_type = ffi::AVMEDIA_TYPE_VIDEO;

let (stream_index, mut decode_context) = {
let (stream_index, decoder) = input_format_context
Expand Down
Loading

0 comments on commit 65e414e

Please sign in to comment.