ffmpeg_the_third/format/stream/
stream_mut.rs1use std::mem;
2use std::ops::Deref;
3
4use super::Stream;
5use crate::ffi::*;
6use crate::format::context::common::Context;
7use crate::AsPtr;
8use crate::{codec, Dictionary, Rational};
9
10pub struct StreamMut<'a> {
11 context: &'a mut Context,
12 index: usize,
13
14 immutable: Stream<'a>,
15}
16
17impl<'a> StreamMut<'a> {
18 pub unsafe fn wrap(context: &mut Context, index: usize) -> StreamMut<'_> {
19 StreamMut {
20 context: mem::transmute_copy(&context),
21 index,
22
23 immutable: Stream::wrap(mem::transmute_copy(&context), index),
24 }
25 }
26
27 pub unsafe fn as_mut_ptr(&mut self) -> *mut AVStream {
28 *(*self.context.as_mut_ptr()).streams.add(self.index)
29 }
30}
31
32impl<'a> StreamMut<'a> {
33 pub fn set_time_base<R: Into<Rational>>(&mut self, value: R) {
34 unsafe {
35 (*self.as_mut_ptr()).time_base = value.into().into();
36 }
37 }
38
39 pub fn set_rate<R: Into<Rational>>(&mut self, value: R) {
40 unsafe {
41 (*self.as_mut_ptr()).r_frame_rate = value.into().into();
42 }
43 }
44
45 pub fn set_avg_frame_rate<R: Into<Rational>>(&mut self, value: R) {
46 unsafe {
47 (*self.as_mut_ptr()).avg_frame_rate = value.into().into();
48 }
49 }
50
51 pub fn parameters_mut(&mut self) -> codec::ParametersMut<'_> {
52 unsafe {
53 codec::ParametersMut::from_raw((*self.as_mut_ptr()).codecpar)
54 .expect("codecpar is non-null")
55 }
56 }
57
58 pub fn set_parameters<P: AsPtr<AVCodecParameters>>(&mut self, parameters: P) {
59 unsafe {
60 avcodec_parameters_copy((*self.as_mut_ptr()).codecpar, parameters.as_ptr());
61 }
62 }
63
64 pub fn copy_parameters_from_context(&mut self, ctx: &codec::Context) {
65 unsafe {
66 avcodec_parameters_from_context((*self.as_mut_ptr()).codecpar, ctx.as_ptr());
67 }
68 }
69
70 pub fn set_metadata(&mut self, metadata: Dictionary) {
71 unsafe {
72 let metadata = metadata.disown();
73 (*self.as_mut_ptr()).metadata = metadata;
74 }
75 }
76}
77
78impl<'a> Deref for StreamMut<'a> {
79 type Target = Stream<'a>;
80
81 fn deref(&self) -> &Self::Target {
82 &self.immutable
83 }
84}