1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//! This crate provides bindings to the MediaCodec APIs in the Android NDK.
//!
//! Examples:
//! ### Decoding
//! ```edition2021
//!
//! # #[no_mangle]
//! # extern "C" fn process() {
//! use mediacodec::{Frame, MediaCodec, MediaExtractor, SampleFormat, VideoFrame};
//! let mut extractor = MediaExtractor::from_url("/path/to/a/resource").unwrap();
//! debug!("Track count: {}", extractor.track_count());
//! let mut decoders = vec![];
//! for i in 0..extractor.track_count() {
//! let format = extractor.track_format(i).unwrap();
//! debug!("{}", format.to_string());
//! let mime_type = format.get_string("mime").unwrap();
//! let mut codec = MediaCodec::create_decoder(&mime_type).unwrap();
//! codec.init(&format, None, 0).unwrap();
//! codec.start().unwrap();
//! decoders.push(codec);
//! extractor.select_track(i);
//! }
//! while extractor.has_next() {
//! // 1. Get the track index
//! let index = extractor.track_index();
//!
//! if index < 0 {
//! break;
//! }
//!
//! let codec = &mut decoders[index as usize];
//!
//! // Fetch the codec's input buffer
//! while let Ok(mut buffer) = codec.dequeue_input() {
//! if !extractor.read_next(&mut buffer) {
//! debug!(
//! "MediaExtractor.read_next() returned false! has_next(): {}",
//! extractor.has_next()
//! );
//! break; // VERY IMPORTANT, there's nothing else to DO, so break!!!
//! }
//!
//! // When the buffer gets dropped (here), the buffer will be queued back to MediaCodec
//! // And we don't have to do anything else
//! }
//!
//! // Check for output
//! let output_fmt = codec.output_format().unwrap();
//! while let Ok(mut buffer) = codec.dequeue_output() {
//! if let Some(ref frame) = buffer.frame() {
//! match frame {
//! Frame::Audio(value) => match value.format() {
//! SampleFormat::S16(_) => {
//! // Do something with the audio frame
//! }
//! SampleFormat::F32(_) => {
//! // Do something with the audio frame
//! }
//! },
//! Frame::Video(value) => match value {
//! VideoFrame::Hardware => {
//! // Nothing TODO. The frame will be rendered
//! }
//! VideoFrame::RawFrame(_) => {
//! // Read out the raw buffers or something
//! }
//! },
//! }
//! }
//!
//! // Set the buffer to render when dropped. Only applicable to video codecs that have a hardware buffer (i.e, attached to a native window)
//! buffer.set_render(true);
//! }
//! }
//! # }
//! ```
//!
//! ### Demuxing
//! ```edition2021
//! use log::debug;
//! use mediacodec::{Frame, MediaExtractor, SampleFormat, VideoFrame};
//!
//! # #[no_mangle]
//! # extern "C" fn process() {
//! let mut extractor = MediaExtractor::from_url("/path/to/a/resource").unwrap();
//!
//! debug!("Track count: {}", extractor.track_count());
//!
//! for i in 0..extractor.track_count() {
//! let format = extractor.track_format(i).unwrap();
//! debug!("{}", format.to_string());
//! let mime_type = format.get_string("mime").unwrap();
//! extractor.select_track(i);
//! }
//!
//! while extractor.has_next() {
//! // 1. Get the track index
//! let index = extractor.track_index();
//!
//! if index < 0 {
//! break;
//! }
//!
//! // Get a codec buffer and read data into it
//! }
//! # }
//! ```
// #![cfg(os = "android")]
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;