New upstream version 0.5.1
Kyle Robbertze
1 year, 10 months ago
0 | version=0.19.0 | |
1 | profile = conventional | |
2 | break-separators = after | |
3 | space-around-lists = false | |
4 | doc-comments = before | |
5 | match-indent = 2 | |
6 | match-indent-nested = always | |
7 | parens-ite | |
8 | exp-grouping = preserve | |
9 | module-item-spacing = compact |
0 | language: c | |
1 | sudo: false | |
2 | addons: | |
3 | apt: | |
4 | packages: | |
5 | - ocaml-nox | |
6 | - ocaml-findlib | |
7 | - libfaad-dev | |
8 | ||
9 | script: ./bootstrap && ./configure && make |
0 | 0.5.1 (20-05-2022) | |
1 | ===== | |
2 | * Switch to `pkg-config` for library detection. | |
3 | * Cleanup warnings | |
4 | ||
0 | 5 | 0.5.0 (07-10-2020) |
1 | 6 | ===== |
2 | 7 | * Convert to Unix.read style API. |
0 | (lang dune 2.0) | |
1 | (version 0.5.0) | |
0 | (lang dune 2.8) | |
1 | (version 0.5.1) | |
2 | 2 | (name faad) |
3 | 3 | (source (github savonet/ocaml-faad)) |
4 | 4 | (license GPL-2.0) |
6 | 6 | (maintainers "Romain Beauxis <toots@rastageeks.org>") |
7 | 7 | |
8 | 8 | (generate_opam_files true) |
9 | (use_standard_c_and_cxx_flags false) | |
9 | 10 | |
10 | 11 | (package |
11 | 12 | (name faad) |
12 | 13 | (synopsis "Bindings for the faad library which provides functions for decoding AAC audio files") |
13 | 14 | (depends |
14 | (dune (> 2.0)) | |
15 | conf-faad | |
16 | conf-pkg-config | |
17 | dune | |
15 | 18 | dune-configurator) |
16 | 19 | ) |
24 | 24 | *) |
25 | 25 | |
26 | 26 | let bufsize = 16 * 1024 |
27 | ||
28 | 27 | let src = ref "" |
29 | 28 | let dst = ref "" |
30 | 29 | |
41 | 40 | let usage = "usage: aac2wav [options] source destination" |
42 | 41 | |
43 | 42 | let () = |
44 | Arg.parse | |
45 | [] | |
46 | ( | |
47 | let pnum = ref (-1) in | |
48 | (fun s -> incr pnum; match !pnum with | |
49 | | 0 -> src := s | |
50 | | 1 -> dst := s | |
51 | | _ -> Printf.eprintf "Error: too many arguments\n"; exit 1 | |
52 | ) | |
53 | ) usage; | |
54 | if !src = "" || !dst = "" then | |
55 | ( | |
56 | Printf.printf "%s\n" usage; | |
57 | exit 1 | |
58 | ); | |
43 | Arg.parse [] | |
44 | (let pnum = ref (-1) in | |
45 | fun s -> | |
46 | incr pnum; | |
47 | match !pnum with | |
48 | | 0 -> src := s | |
49 | | 1 -> dst := s | |
50 | | _ -> | |
51 | Printf.eprintf "Error: too many arguments\n"; | |
52 | exit 1) | |
53 | usage; | |
54 | if !src = "" || !dst = "" then ( | |
55 | Printf.printf "%s\n" usage; | |
56 | exit 1); | |
59 | 57 | |
60 | 58 | let buflen = 1024 in |
61 | 59 | let buf = Bytes.create buflen in |
70 | 68 | for c = 0 to channels - 1 do |
71 | 69 | let n = a.(c).(i) *. 32767. in |
72 | 70 | let n = int_of_float n in |
73 | Bytes.set tmp (2 * (i * channels + c)) (char_of_int (n land 0xff)); | |
74 | Bytes.set tmp (2 * (i * channels + c) + 1) (char_of_int ((n lsr 8) land 0xff)); | |
71 | Bytes.set tmp (2 * ((i * channels) + c)) (char_of_int (n land 0xff)); | |
72 | Bytes.set tmp | |
73 | ((2 * ((i * channels) + c)) + 1) | |
74 | (char_of_int ((n lsr 8) land 0xff)) | |
75 | 75 | done |
76 | 76 | done; |
77 | outbuf := !outbuf ^ (Bytes.to_string tmp) | |
77 | outbuf := !outbuf ^ Bytes.to_string tmp | |
78 | 78 | in |
79 | 79 | |
80 | 80 | let decode_mp4 () = |
84 | 84 | let fill_out = fill_out channels in |
85 | 85 | let samples = Faad.Mp4.samples mp4 track in |
86 | 86 | Printf.printf "Input file: %d channels at %d Hz.\n%!" channels samplerate; |
87 | Array.iter (fun (i,t) -> Printf.printf "%s: %s\n%!" i t) (Faad.Mp4.metadata mp4); | |
87 | Array.iter | |
88 | (fun (i, t) -> Printf.printf "%s: %s\n%!" i t) | |
89 | (Faad.Mp4.metadata mp4); | |
88 | 90 | Printf.printf "%d tracks (AAC track: %d).\n%!" (Faad.Mp4.tracks mp4) track; |
89 | 91 | Printf.printf "%d samples.\n" samples; |
90 | 92 | for i = 0 to samples - 1 do |
91 | Printf.printf "Decoding sample: %d / %d (%d bytes).\r%!" i samples (String.length !outbuf); | |
93 | Printf.printf "Decoding sample: %d / %d (%d bytes).\r%!" i samples | |
94 | (String.length !outbuf); | |
92 | 95 | let a = Faad.Mp4.decode mp4 track i dec in |
93 | 96 | fill_out a |
94 | 97 | done; |
95 | 98 | Printf.printf "\n%!"; |
96 | channels, samplerate, !outbuf | |
99 | (channels, samplerate, !outbuf) | |
97 | 100 | in |
98 | 101 | |
99 | 102 | let decode_aac () = |
100 | 103 | let len = Unix.read f buf 0 buflen in |
101 | 104 | let offset, samplerate, channels = Faad.init dec buf 0 len in |
102 | let buflen = Faad.min_bytes_per_channel * channels in | |
105 | let buflen = Faad.min_bytes_per_channel * channels in | |
103 | 106 | let consumed = ref buflen in |
104 | 107 | let aacbuf = Bytes.create buflen in |
105 | 108 | |
108 | 111 | while !consumed <> 0 do |
109 | 112 | let n = Unix.read f aacbuf (buflen - !consumed) !consumed in |
110 | 113 | if n = 0 then raise End_of_file; |
111 | consumed := !consumed - n; | |
114 | consumed := !consumed - n | |
112 | 115 | done |
113 | 116 | in |
114 | 117 | |
125 | 128 | consumed := c; |
126 | 129 | fill_out a |
127 | 130 | done; |
128 | channels, samplerate, !outbuf | |
131 | (channels, samplerate, !outbuf) | |
129 | 132 | with |
130 | | End_of_file | |
131 | | Faad.Failed -> | |
132 | channels, samplerate, !outbuf | |
133 | | Faad.Error n as e -> | |
134 | Printf.printf "Faad error %d: %s\n%!" n (Faad.error_message n); | |
135 | raise e | |
133 | | End_of_file | Faad.Failed -> (channels, samplerate, !outbuf) | |
134 | | Faad.Error n as e -> | |
135 | Printf.printf "Faad error %d: %s\n%!" n (Faad.error_message n); | |
136 | raise e | |
136 | 137 | in |
137 | 138 | |
138 | 139 | let channels, samplerate, outbuf = |
139 | if Filename.check_suffix !src ".aac" || Filename.check_suffix !src ".AAC" then | |
140 | decode_aac () | |
141 | else | |
142 | decode_mp4 () | |
140 | if Filename.check_suffix !src ".aac" || Filename.check_suffix !src ".AAC" | |
141 | then decode_aac () | |
142 | else decode_mp4 () | |
143 | 143 | in |
144 | 144 | |
145 | 145 | (* Do the wav stuff. *) |
150 | 150 | output_string oc "WAVE"; |
151 | 151 | output_string oc "fmt "; |
152 | 152 | output_int oc 16; |
153 | output_short oc 1; (* WAVE_FORMAT_PCM *) | |
154 | output_short oc channels; (* channels *) | |
155 | output_int oc samplerate; (* freq *) | |
156 | output_int oc (samplerate * channels * 2); (* bytes / s *) | |
157 | output_short oc (channels * 2); (* block alignment *) | |
158 | output_short oc 16; (* bits per sample *) | |
153 | output_short oc 1; | |
154 | (* WAVE_FORMAT_PCM *) | |
155 | output_short oc channels; | |
156 | (* channels *) | |
157 | output_int oc samplerate; | |
158 | (* freq *) | |
159 | output_int oc (samplerate * channels * 2); | |
160 | (* bytes / s *) | |
161 | output_short oc (channels * 2); | |
162 | (* block alignment *) | |
163 | output_short oc 16; | |
164 | (* bits per sample *) | |
159 | 165 | output_string oc "data"; |
160 | 166 | output_int oc datalen; |
161 | 167 | output_string oc outbuf; |
0 | 0 | # This file is generated by dune, edit dune-project instead |
1 | 1 | opam-version: "2.0" |
2 | version: "0.5.0" | |
2 | version: "0.5.1" | |
3 | 3 | synopsis: |
4 | 4 | "Bindings for the faad library which provides functions for decoding AAC audio files" |
5 | 5 | maintainer: ["Romain Beauxis <toots@rastageeks.org>"] |
8 | 8 | homepage: "https://github.com/savonet/ocaml-faad" |
9 | 9 | bug-reports: "https://github.com/savonet/ocaml-faad/issues" |
10 | 10 | depends: [ |
11 | "dune" {> "2.0"} | |
11 | "conf-faad" | |
12 | "conf-pkg-config" | |
13 | "dune" {>= "2.8"} | |
12 | 14 | "dune-configurator" |
15 | "odoc" {with-doc} | |
13 | 16 | ] |
14 | 17 | build: [ |
15 | ["dune" "subst"] {pinned} | |
18 | ["dune" "subst"] {dev} | |
16 | 19 | [ |
17 | 20 | "dune" |
18 | 21 | "build" |
26 | 29 | ] |
27 | 30 | ] |
28 | 31 | dev-repo: "git+https://github.com/savonet/ocaml-faad.git" |
29 | depexts: [ | |
30 | ["faad2-dev"] {os-distribution = "alpine"} | |
31 | ["faad2"] {os-distribution = "arch"} | |
32 | ["faad2-devel"] {os-distribution = "centos"} | |
33 | ["faad2-devel"] {os-distribution = "fedora"} | |
34 | ["faad2-devel"] {os-family = "suse"} | |
35 | ["libfaad-dev"] {os-family = "debian"} | |
36 | ["faad2"] {os = "macos" & os-distribution = "homebrew"} | |
37 | ] |
0 | depexts: [ | |
1 | ["faad2-dev"] {os-distribution = "alpine"} | |
2 | ["faad2"] {os-distribution = "arch"} | |
3 | ["faad2-devel"] {os-distribution = "centos"} | |
4 | ["faad2-devel"] {os-distribution = "fedora"} | |
5 | ["faad2-devel"] {os-family = "suse"} | |
6 | ["libfaad-dev"] {os-family = "debian"} | |
7 | ["faad2"] {os = "macos" & os-distribution = "homebrew"} | |
8 | ] |
0 | 0 | module C = Configurator.V1 |
1 | 1 | |
2 | let faad_test_code = {| | |
3 | #include <neaacdec.h> | |
4 | ||
5 | int main() | |
6 | { | |
7 | NeAACDecHandle hAac = NeAACDecOpen(); | |
8 | unsigned char input[1024]; | |
9 | size_t input_size = 0; | |
10 | unsigned long samplerate; | |
11 | unsigned char channels; | |
12 | ||
13 | char err = NeAACDecInit(hAac, input, input_size, &samplerate, &channels); | |
14 | ||
15 | return 0; | |
16 | } | |
17 | |} | |
18 | ||
19 | 2 | let () = |
20 | C.main ~name:"has_faad" (fun c -> | |
21 | let has_faad = C.c_test c faad_test_code ~link_flags:["-lfaad -lm"] in | |
22 | ||
23 | C.C_define.gen_header_file c ~fname:"config.h" | |
24 | [ "HAS_FAAD", Switch has_faad ]); | |
3 | C.main ~name:"faad2-pkg-config" (fun c -> | |
4 | let default : C.Pkg_config.package_conf = | |
5 | { libs = ["-lfaad2"]; cflags = [] } | |
6 | in | |
7 | let conf = | |
8 | match C.Pkg_config.get c with | |
9 | | None -> default | |
10 | | Some pc -> ( | |
11 | match | |
12 | C.Pkg_config.query_expr_err pc ~package:"faad2" ~expr:"faad2" | |
13 | with | |
14 | | Error msg -> failwith msg | |
15 | | Ok deps -> deps) | |
16 | in | |
17 | C.Flags.write_sexp "c_flags.sexp" conf.cflags; | |
18 | C.Flags.write_sexp "c_library_flags.sexp" conf.libs) |
3 | 3 | (synopsis "Ocaml bindings to libfaad") |
4 | 4 | (foreign_stubs |
5 | 5 | (language c) |
6 | (extra_deps config.h) | |
7 | (names | |
8 | faad_stubs | |
9 | mp4atom | |
10 | mp4ff | |
11 | mp4meta | |
12 | mp4sample | |
13 | mp4tagupdate | |
14 | mp4util) | |
15 | (flags -DUSE_TAGGING)) | |
16 | (c_library_flags "-lfaad -lm")) | |
6 | (names faad_stubs mp4atom mp4ff mp4meta mp4sample mp4tagupdate mp4util) | |
7 | (flags | |
8 | -DUSE_TAGGING | |
9 | (:include c_flags.sexp))) | |
10 | (c_library_flags | |
11 | (:include c_library_flags.sexp))) | |
17 | 12 | |
18 | 13 | (rule |
19 | (targets config.h) | |
20 | (action (run ./config/discover.exe))) | |
14 | (targets c_flags.sexp c_library_flags.sexp) | |
15 | (action | |
16 | (run ./config/discover.exe))) |
19 | 19 | type t |
20 | 20 | |
21 | 21 | exception Error of int |
22 | ||
23 | 22 | exception Failed |
24 | 23 | |
25 | 24 | external error_message : int -> string = "ocaml_faad_get_error_message" |
28 | 27 | Callback.register_exception "ocaml_faad_exn_error" (Error 0); |
29 | 28 | Callback.register_exception "ocaml_faad_exn_failed" Failed |
30 | 29 | |
31 | external min_bytes_per_channel : unit -> int = "ocaml_faad_min_bytes_per_channel" | |
30 | external min_bytes_per_channel : unit -> int | |
31 | = "ocaml_faad_min_bytes_per_channel" | |
32 | 32 | |
33 | 33 | let min_bytes_per_channel = min_bytes_per_channel () |
34 | 34 | |
35 | 35 | external create : unit -> t = "ocaml_faad_open" |
36 | 36 | |
37 | external init : t -> Bytes.t -> int -> int -> int * int * int = "ocaml_faad_init" | |
37 | external init : t -> Bytes.t -> int -> int -> int * int * int | |
38 | = "ocaml_faad_init" | |
38 | 39 | |
39 | external decode : t -> Bytes.t -> int -> int -> int * (float array array) = "ocaml_faad_decode" | |
40 | external decode : t -> Bytes.t -> int -> int -> int * float array array | |
41 | = "ocaml_faad_decode" | |
40 | 42 | |
41 | 43 | external post_sync_reset : t -> unit = "ocaml_faad_post_seek_reset" |
42 | 44 | |
43 | 45 | let find_frame buf = |
44 | 46 | let i = ref 0 in |
45 | 47 | let found = ref false in |
46 | while !i < String.length buf - 1 && not !found do | |
47 | if buf.[!i] = '\255' then | |
48 | if int_of_char buf.[!i+1] land 0xf6 = 0xf0 then | |
49 | found := true | |
50 | else | |
51 | incr i | |
52 | else | |
53 | incr i | |
54 | done; | |
55 | if !found then !i else raise Not_found | |
48 | while !i < String.length buf - 1 && not !found do | |
49 | if buf.[!i] = '\255' then | |
50 | if int_of_char buf.[!i + 1] land 0xf6 = 0xf0 then found := true | |
51 | else incr i | |
52 | else incr i | |
53 | done; | |
54 | if !found then !i else raise Not_found | |
56 | 55 | |
57 | module Mp4 = | |
58 | struct | |
56 | module Mp4 = struct | |
59 | 57 | type decoder = t |
60 | ||
61 | 58 | type t |
62 | ||
63 | 59 | type track = int |
64 | ||
65 | 60 | type sample = int |
66 | ||
67 | 61 | type read = bytes -> int -> int -> int |
68 | 62 | |
69 | 63 | let is_mp4 s = |
70 | 64 | assert (String.length s >= 8); |
71 | 65 | s.[4] = 'f' && s.[5] = 't' && s.[6] = 'y' && s.[7] = 'p' |
72 | 66 | |
73 | external open_read : bool -> read -> (Bytes.t -> int) option -> (int -> int) option -> (unit -> int) option -> t = "ocaml_faad_mp4_open_read" | |
67 | external open_read : | |
68 | bool -> | |
69 | read -> | |
70 | (Bytes.t -> int) option -> | |
71 | (int -> int) option -> | |
72 | (unit -> int) option -> | |
73 | t = "ocaml_faad_mp4_open_read" | |
74 | 74 | |
75 | external open_read_fd : bool -> Unix.file_descr -> t = "ocaml_faad_mp4_open_read_fd" | |
75 | external open_read_fd : bool -> Unix.file_descr -> t | |
76 | = "ocaml_faad_mp4_open_read_fd" | |
76 | 77 | |
77 | 78 | let openfile ?write ?seek ?trunc read = open_read false read write seek trunc |
78 | ||
79 | 79 | let openfile_fd = open_read_fd false |
80 | 80 | |
81 | external seek : t -> track -> int -> int*int = "ocaml_faad_mp4_seek" | |
81 | external seek : t -> track -> int -> int * int = "ocaml_faad_mp4_seek" | |
82 | 82 | |
83 | let seek mp4 track offset = | |
84 | let sample,to_skip = seek mp4 track offset in | |
85 | if sample < 0 then | |
86 | raise Failed | |
87 | else | |
88 | sample,to_skip | |
83 | let seek mp4 track offset = | |
84 | let sample, to_skip = seek mp4 track offset in | |
85 | if sample < 0 then raise Failed else (sample, to_skip) | |
89 | 86 | |
90 | 87 | external tracks : t -> int = "ocaml_faad_mp4_total_tracks" |
91 | ||
92 | 88 | external find_aac_track : t -> track = "ocaml_faad_mp4_find_aac_track" |
93 | ||
94 | 89 | external init : t -> decoder -> track -> int * int = "ocaml_faad_mp4_init" |
95 | ||
96 | 90 | external samples : t -> track -> int = "ocaml_faad_mp4_num_samples" |
97 | 91 | |
98 | external read_sample : t -> track -> sample -> string = "ocaml_faad_mp4_read_sample" | |
92 | external read_sample : t -> track -> sample -> string | |
93 | = "ocaml_faad_mp4_read_sample" | |
99 | 94 | |
100 | external decode : t -> track -> sample -> decoder -> float array array = "ocaml_faad_mp4_decode" | |
95 | external decode : t -> track -> sample -> decoder -> float array array | |
96 | = "ocaml_faad_mp4_decode" | |
101 | 97 | |
102 | 98 | external metadata : t -> (string * string) array = "ocaml_faad_mp4_metadata" |
103 | 99 | end |
104 |
27 | 27 | |
28 | 28 | (** An error occured... *) |
29 | 29 | exception Error of int |
30 | ||
30 | 31 | exception Failed |
31 | 32 | |
32 | 33 | (** Get the error message corresponding to a raised [Error]. *) |
48 | 49 | * starting at offset [ofs]. It returns the number of bytes actually decoded |
49 | 50 | * and the decoded data (non-interleaved). |
50 | 51 | *) |
51 | val decode : t -> Bytes.t -> int -> int -> int * (float array array) | |
52 | val decode : t -> Bytes.t -> int -> int -> int * float array array | |
52 | 53 | |
53 | 54 | val post_sync_reset : t -> unit |
54 | 55 | |
55 | 56 | (** Heuristic guess of the offset of the begining of a frame. *) |
56 | 57 | val find_frame : string -> int |
57 | 58 | |
58 | module Mp4 : | |
59 | sig | |
59 | module Mp4 : sig | |
60 | 60 | type decoder = t |
61 | 61 | |
62 | 62 | (** An MP4 reader. *) |
75 | 75 | val is_mp4 : string -> bool |
76 | 76 | |
77 | 77 | (** Open an MP4 file. *) |
78 | val openfile : ?write:(Bytes.t -> int) -> | |
79 | ?seek:(int -> int) -> | |
80 | ?trunc:(unit -> int) -> read -> t | |
78 | val openfile : | |
79 | ?write:(Bytes.t -> int) -> | |
80 | ?seek:(int -> int) -> | |
81 | ?trunc:(unit -> int) -> | |
82 | read -> | |
83 | t | |
81 | 84 | |
82 | 85 | val openfile_fd : Unix.file_descr -> t |
83 | 86 | |
95 | 98 | * [sample] is the new current (mp4) sample |
96 | 99 | * and [toskip] is an amount of audio sample |
97 | 100 | * that should be skipped. *) |
98 | val seek : t -> track -> int -> int*int | |
101 | val seek : t -> track -> int -> int * int | |
99 | 102 | |
100 | 103 | val samples : t -> track -> int |
101 | ||
102 | 104 | val read_sample : t -> track -> sample -> string |
103 | ||
104 | 105 | val decode : t -> track -> sample -> decoder -> float array array |
105 | ||
106 | 106 | val metadata : t -> (string * string) array |
107 | 107 | end |
501 | 501 | mp4_t *mp = Mp4_val(m); |
502 | 502 | int t = Int_val(track); |
503 | 503 | int s = Int_val(sample); |
504 | unsigned char *buf = NULL; | |
504 | int8_t *buf = NULL; | |
505 | 505 | unsigned int buflen = 0; |
506 | 506 | int ret; |
507 | 507 | |
511 | 511 | check_err(ret); |
512 | 512 | |
513 | 513 | ans = caml_alloc_string(buflen); |
514 | memcpy(String_val(ans), buf, buflen); | |
514 | memcpy((void *)String_val(ans), buf, buflen); | |
515 | 515 | free(buf); |
516 | 516 | |
517 | 517 | CAMLreturn(ans); |
527 | 527 | int s = Int_val(sample); |
528 | 528 | NeAACDecHandle dec = Dec_val(dh); |
529 | 529 | NeAACDecFrameInfo frameInfo; |
530 | unsigned char *inbuf = NULL; | |
530 | int8_t *inbuf = NULL; | |
531 | 531 | unsigned int inbuflen = 0; |
532 | 532 | float *data; |
533 | 533 | int c, i, ret; |
539 | 539 | check_err(ret); |
540 | 540 | |
541 | 541 | caml_release_runtime_system(); |
542 | data = NeAACDecDecode(dec, &frameInfo, inbuf, inbuflen); | |
542 | data = NeAACDecDecode(dec, &frameInfo, (uint8_t *)inbuf, inbuflen); | |
543 | 543 | caml_acquire_runtime_system(); |
544 | 544 | |
545 | 545 | free(inbuf); |
436 | 436 | } |
437 | 437 | |
438 | 438 | int32_t mp4ff_read_sample(mp4ff_t *f, const int32_t track, const int32_t sample, |
439 | uint8_t **audio_buffer, uint32_t *bytes) | |
439 | int8_t **audio_buffer, uint32_t *bytes) | |
440 | 440 | { |
441 | 441 | int32_t result = 0; |
442 | 442 | |
444 | 444 | |
445 | 445 | if (*bytes==0) return 0; |
446 | 446 | |
447 | *audio_buffer = (uint8_t*)malloc(*bytes); | |
447 | *audio_buffer = (int8_t*)malloc(*bytes); | |
448 | 448 | |
449 | 449 | mp4ff_set_sample_position(f, track, sample); |
450 | 450 | |
474 | 474 | int32_t size = mp4ff_audio_frame_size(f,track,sample); |
475 | 475 | if (size<=0) return 0; |
476 | 476 | mp4ff_set_sample_position(f, track, sample); |
477 | result = mp4ff_read_data(f,buffer,size); | |
477 | result = mp4ff_read_data(f,(int8_t *)buffer,size); | |
478 | 478 | |
479 | 479 | #ifdef ITUNES_DRM |
480 | 480 | if (f->track[track]->p_drms != NULL) |
110 | 110 | int32_t *ctts_sample_offset; |
111 | 111 | |
112 | 112 | /* esde */ |
113 | uint8_t *decoderConfig; | |
113 | int8_t *decoderConfig; | |
114 | 114 | int32_t decoderConfigLen; |
115 | 115 | |
116 | 116 | uint32_t maxBitrate; |
164 | 164 | int32_t mp4ff_find_sample_use_offsets(const mp4ff_t *f, const int32_t track, const int64_t offset,int32_t * toskip); |
165 | 165 | |
166 | 166 | int32_t mp4ff_read_sample(mp4ff_t *f, const int track, const int sample, |
167 | unsigned char **audio_buffer, unsigned int *bytes); | |
167 | int8_t **audio_buffer, unsigned int *bytes); | |
168 | 168 | |
169 | 169 | int32_t mp4ff_read_sample_v2(mp4ff_t *f, const int track, const int sample,unsigned char *buffer);//returns 0 on error, number of bytes read on success, use mp4ff_read_sample_getsize() to check buffer size needed |
170 | 170 | int32_t mp4ff_read_sample_getsize(mp4ff_t *f, const int track, const int sample);//returns 0 on error, buffer size needed for mp4ff_read_sample_v2() on success |
219 | 219 | int32_t mp4ff_find_sample(const mp4ff_t *f, const int32_t track, const int64_t offset,int32_t * toskip); |
220 | 220 | |
221 | 221 | int32_t mp4ff_read_sample(mp4ff_t *f, const int32_t track, const int32_t sample, |
222 | uint8_t **audio_buffer, uint32_t *bytes); | |
222 | int8_t **audio_buffer, uint32_t *bytes); | |
223 | 223 | int32_t mp4ff_get_decoder_config(const mp4ff_t *f, const int32_t track, |
224 | 224 | uint8_t** ppBuf, uint32_t* pBufSize); |
225 | 225 | int32_t mp4ff_total_tracks(const mp4ff_t *f); |
142 | 142 | bufptr = membuffer_get_ptr(buf); |
143 | 143 | if (bufptr==0) return 0; |
144 | 144 | |
145 | if ((unsigned)mp4ff_read_data(src,(char*)bufptr + oldsize,bytes)!=bytes) | |
145 | if ((unsigned)mp4ff_read_data(src,(int8_t *)bufptr + oldsize,bytes)!=bytes) | |
146 | 146 | { |
147 | 147 | membuffer_set_error(buf); |
148 | 148 | return 0; |
364 | 364 | { |
365 | 365 | uint32_t index = mp4ff_meta_genre_to_index(genre_ptr); |
366 | 366 | if (index==0) |
367 | membuffer_write_std_tag(buf,"©gen",genre_ptr); | |
367 | membuffer_write_std_tag(buf,"\u0040gen",genre_ptr); | |
368 | 368 | else |
369 | 369 | membuffer_write_int16_tag(buf,"gnre",(uint16_t)index); |
370 | 370 | } |
416 | 416 | if (remaining < 8) break; |
417 | 417 | atom_size = mp4ff_read_int32(f); |
418 | 418 | if (atom_size > remaining || atom_size < 8) break; |
419 | mp4ff_read_data(f,atom_name,4); | |
419 | mp4ff_read_data(f,(int8_t *)atom_name,4); | |
420 | 420 | |
421 | 421 | if (!memcmp(atom_name,name,4)) |
422 | 422 | { |
511 | 511 | uint32_t new_ilst_size; |
512 | 512 | void * new_ilst_buffer; |
513 | 513 | |
514 | uint8_t * p_out; | |
514 | int8_t * p_out; | |
515 | 515 | int32_t size_delta; |
516 | 516 | |
517 | 517 | |
580 | 580 | return 0; |
581 | 581 | } |
582 | 582 | |
583 | p_out = (uint8_t*)*out_buffer; | |
583 | p_out = (int8_t*)*out_buffer; | |
584 | 584 | |
585 | 585 | mp4ff_set_position(f,total_base); |
586 | 586 | mp4ff_read_data(f,p_out,(uint32_t)(udta_offset - total_base )); p_out += (uint32_t)(udta_offset - total_base ); |
632 | 632 | |
633 | 633 | /* rename old moov to free */ |
634 | 634 | mp4ff_set_position(ff, ff->moov_offset + 4); |
635 | mp4ff_write_data(ff, free_data, 4); | |
635 | mp4ff_write_data(ff, (int8_t *)free_data, 4); | |
636 | 636 | |
637 | 637 | mp4ff_set_position(ff, ff->file_size); |
638 | 638 | mp4ff_write_int32(ff,new_moov_size + 8); |
639 | mp4ff_write_data(ff,"moov",4); | |
639 | mp4ff_write_data(ff,(int8_t *)"moov",4); | |
640 | 640 | mp4ff_write_data(ff, new_moov_data, new_moov_size); |
641 | 641 | } |
642 | 642 | else |
643 | 643 | { |
644 | 644 | mp4ff_set_position(ff, ff->moov_offset); |
645 | 645 | mp4ff_write_int32(ff,new_moov_size + 8); |
646 | mp4ff_write_data(ff,"moov",4); | |
646 | mp4ff_write_data(ff,(int8_t *)"moov",4); | |
647 | 647 | mp4ff_write_data(ff, new_moov_data, new_moov_size); |
648 | 648 | } |
649 | 649 |
74 | 74 | |
75 | 75 | result = (a<<24) | (b<<16) | (c<<8) | d; |
76 | 76 | |
77 | return mp4ff_write_data(f,(uint8_t*)&result,sizeof(result)); | |
77 | return mp4ff_write_data(f,(int8_t*)&result,sizeof(result)); | |
78 | 78 | } |
79 | 79 | |
80 | 80 | int32_t mp4ff_set_position(mp4ff_t *f, const int64_t position) |
92 | 92 | |
93 | 93 | uint64_t mp4ff_read_int64(mp4ff_t *f) |
94 | 94 | { |
95 | uint8_t data[8]; | |
95 | int8_t data[8]; | |
96 | 96 | uint64_t result = 0; |
97 | 97 | int8_t i; |
98 | 98 | |
156 | 156 | char * str = (char*)malloc(length + 1); |
157 | 157 | if (str!=0) |
158 | 158 | { |
159 | if ((uint32_t)mp4ff_read_data(f,str,length)!=length) | |
159 | if ((uint32_t)mp4ff_read_data(f,(int8_t *)str,length)!=length) | |
160 | 160 | { |
161 | 161 | free(str); |
162 | 162 | str = 0; |
171 | 171 | |
172 | 172 | uint8_t mp4ff_read_char(mp4ff_t *f) |
173 | 173 | { |
174 | uint8_t output; | |
174 | int8_t output; | |
175 | 175 | mp4ff_read_data(f, &output, 1); |
176 | 176 | return output; |
177 | 177 | } |