Skip to content

Commit 8a1b279

Browse files
committed
extra stuff from c macros
1 parent 8347e5a commit 8a1b279

File tree

4 files changed

+120
-30
lines changed

4 files changed

+120
-30
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ tar = "0.4.26"
1919
flate2 = "1.0.12"
2020
bindgen = "0.51"
2121
num_cpus = "1.11.1"
22+
cc = "1.0.46"

build.rs

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -365,35 +365,13 @@ fn build() {
365365
.expect("Couldn't write bindings!");
366366
}
367367
}
368-
// DEV - TMP
369-
// {
370-
// let codegen = |file_name: &str, headers: &[&str]| {
371-
// let codegen = bindgen::Builder::default();
372-
// let codegen = headers
373-
// .iter()
374-
// .fold(codegen, |codegen: bindgen::Builder, path: &&str| -> bindgen::Builder {
375-
// let path: &str = path.clone();
376-
// let path: PathBuf = source_path.join(path);
377-
// let path: &str = path.to_str().expect("PathBuf to str");
378-
// assert!(PathBuf::from(path).exists());
379-
// codegen.header(path)
380-
// });
381-
// codegen
382-
// .layout_tests(false)
383-
// .generate_comments(true)
384-
// .generate()
385-
// .expect("Unable to generate bindings")
386-
// .write_to_file(out_path.join(file_name))
387-
// .expect("Couldn't write bindings!");
388-
// };
389-
// codegen("bindings_avcodec.rs", &["libavcodec/avcodec.h"]);
390-
// codegen("bindings_avdevice.rs", &["libavdevice/avdevice.h"]);
391-
// codegen("bindings_avfilter.rs", &["libavfilter/avfilter.h"]);
392-
// codegen("bindings_avformat.rs", &["libavformat/avformat.h"]);
393-
// codegen("bindings_avresample.rs", &["libavresample/avresample.h"]);
394-
// codegen("bindings_avutil.rs", &["libavutil/avutil.h"]);
395-
// codegen("bindings_swresample.rs", &["libswresample/swresample.h"]);
396-
// }
368+
// COMPILE CBITS
369+
cc::Build::new()
370+
.include({
371+
source_path.to_str().expect("PathBuf to str")
372+
})
373+
.file("cbits.c")
374+
.compile("cbits");
397375
}
398376

399377
///////////////////////////////////////////////////////////////////////////////

cbits.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <libavutil/error.h>
4+
#include <libavutil/avutil.h>
5+
6+
int SYS_EAGAIN() {
7+
return EAGAIN;
8+
}
9+
int SYS_AVERROR(int code) {
10+
return AVERROR(code);
11+
}
12+
int64_t SYS_AV_NOPTS_VALUE() {
13+
return AV_NOPTS_VALUE;
14+
}
15+
int SYS_AV_ERROR_MAX_STRING_SIZE() {
16+
return AV_ERROR_MAX_STRING_SIZE;
17+
}
18+
int SYS_AVERROR_BSF_NOT_FOUND() {
19+
return AVERROR_BSF_NOT_FOUND;
20+
}
21+
int SYS_AVERROR_BUG() {
22+
return AVERROR_BUG;
23+
}
24+
int SYS_AVERROR_BUFFER_TOO_SMALL() {
25+
return AVERROR_BUFFER_TOO_SMALL;
26+
}
27+
int SYS_AVERROR_DECODER_NOT_FOUND() {
28+
return AVERROR_DECODER_NOT_FOUND;
29+
}
30+
int SYS_AVERROR_DEMUXER_NOT_FOUND() {
31+
return AVERROR_DEMUXER_NOT_FOUND;
32+
}
33+
int SYS_AVERROR_ENCODER_NOT_FOUND() {
34+
return AVERROR_ENCODER_NOT_FOUND;
35+
}
36+
int SYS_AVERROR_EOF() {
37+
return AVERROR_EOF;
38+
}
39+
int SYS_AVERROR_EXIT() {
40+
return AVERROR_EXIT;
41+
}
42+
int SYS_AVERROR_EXTERNAL() {
43+
return AVERROR_EXTERNAL;
44+
}
45+
int SYS_AVERROR_FILTER_NOT_FOUND() {
46+
return AVERROR_FILTER_NOT_FOUND;
47+
}
48+
int SYS_AVERROR_INVALIDDATA() {
49+
return AVERROR_INVALIDDATA;
50+
}
51+
int SYS_AVERROR_MUXER_NOT_FOUND() {
52+
return AVERROR_MUXER_NOT_FOUND;
53+
}
54+
int SYS_AVERROR_OPTION_NOT_FOUND() {
55+
return AVERROR_OPTION_NOT_FOUND;
56+
}
57+
int SYS_AVERROR_PATCHWELCOME() {
58+
return AVERROR_PATCHWELCOME;
59+
}
60+
int SYS_AVERROR_PROTOCOL_NOT_FOUND() {
61+
return AVERROR_PROTOCOL_NOT_FOUND;
62+
}
63+
int SYS_AVERROR_STREAM_NOT_FOUND() {
64+
return AVERROR_STREAM_NOT_FOUND;
65+
}

src/extra.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,49 @@
11
//! extra stuff
2+
use std::ffi::{CString, c_void};
3+
use std::os::raw::{c_char, c_int};
4+
use libc::{size_t, c_float};
25

3-
pub const NOPTS_VALUE: i64 = -9223372036854775808;
6+
7+
#[link(name = "cbits")]
8+
extern "C" {
9+
#[link_name = "SYS_EAGAIN"]
10+
fn sys_eagain() -> i32;
11+
#[link_name = "SYS_AVERROR"]
12+
fn sys_sys_averror(code: i32) -> i32;
13+
#[link_name = "SYS_AV_NOPTS_VALUE"]
14+
fn sys_av_nopts_value() -> i64;
15+
#[link_name = "SYS_AV_ERROR_MAX_STRING_SIZE"]
16+
fn av_error_max_string_size() -> c_int;
17+
#[link_name = "SYS_AVERROR_BSF_NOT_FOUND"]
18+
fn averror_bsf_not_found() -> c_int;
19+
#[link_name = "SYS_AVERROR_BUG"]
20+
fn averror_bug() -> c_int;
21+
#[link_name = "SYS_AVERROR_BUFFER_TOO_SMALL"]
22+
fn averror_buffer_too_small() -> c_int;
23+
#[link_name = "SYS_AVERROR_DECODER_NOT_FOUND"]
24+
fn averror_decoder_not_found() -> c_int;
25+
#[link_name = "SYS_AVERROR_DEMUXER_NOT_FOUND"]
26+
fn averror_demuxer_not_found() -> c_int;
27+
#[link_name = "SYS_AVERROR_ENCODER_NOT_FOUND"]
28+
fn averror_encoder_not_found() -> c_int;
29+
#[link_name = "SYS_AVERROR_EOF"]
30+
fn averror_eof() -> c_int;
31+
#[link_name = "SYS_AVERROR_EXIT"]
32+
fn averror_exit() -> c_int;
33+
#[link_name = "SYS_AVERROR_EXTERNAL"]
34+
fn averror_external() -> c_int;
35+
#[link_name = "SYS_AVERROR_FILTER_NOT_FOUND"]
36+
fn averror_filter_not_found() -> c_int;
37+
#[link_name = "SYS_AVERROR_INVALIDDATA"]
38+
fn averror_invaliddata() -> c_int;
39+
#[link_name = "SYS_AVERROR_MUXER_NOT_FOUND"]
40+
fn averror_muxer_not_found() -> c_int;
41+
#[link_name = "SYS_AVERROR_OPTION_NOT_FOUND"]
42+
fn averror_option_not_found() -> c_int;
43+
#[link_name = "SYS_AVERROR_PATCHWELCOME"]
44+
fn averror_patchwelcome() -> c_int;
45+
#[link_name = "SYS_AVERROR_PROTOCOL_NOT_FOUND"]
46+
fn averror_protocol_not_found() -> c_int;
47+
#[link_name = "SYS_AVERROR_STREAM_NOT_FOUND"]
48+
fn averror_stream_not_found() -> c_int;
49+
}

0 commit comments

Comments
 (0)