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