|
| 1 | +(***************************************************************************** |
| 2 | +
|
| 3 | + Liquidsoap, a programmable audio stream generator. |
| 4 | + Copyright 2003-2020 Savonet team |
| 5 | +
|
| 6 | + This program is free software; you can redistribute it and/or modify |
| 7 | + it under the terms of the GNU General Public License as published by |
| 8 | + the Free Software Foundation; either version 2 of the License, or |
| 9 | + (at your option) any later version. |
| 10 | +
|
| 11 | + This program is distributed in the hope that it will be useful, |
| 12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + GNU General Public License for more details, fully stated in the COPYING |
| 15 | + file at the root of the liquidsoap distribution. |
| 16 | +
|
| 17 | + You should have received a copy of the GNU General Public License |
| 18 | + along with this program; if not, write to the Free Software |
| 19 | + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | +
|
| 21 | + *****************************************************************************) |
| 22 | + |
| 23 | +(** Common infrastructure for encoding streams *) |
| 24 | + |
| 25 | +type format = |
| 26 | + | WAV of Wav_format.t |
| 27 | + | AVI of Avi_format.t |
| 28 | + | Ogg of Ogg_format.t |
| 29 | + | MP3 of Mp3_format.t |
| 30 | + | Shine of Shine_format.t |
| 31 | + | Flac of Flac_format.t |
| 32 | + | Ffmpeg of Ffmpeg_format.t |
| 33 | + | FdkAacEnc of Fdkaac_format.t |
| 34 | + | External of External_encoder_format.t |
| 35 | + | GStreamer of Gstreamer_format.t |
| 36 | + |
| 37 | +val audio_kind : int -> Frame.kind Frame.fields |
| 38 | +val audio_video_kind : int -> Frame.kind Frame.fields |
| 39 | +val kind_of_format : format -> Frame.kind Frame.fields |
| 40 | +val string_of_format : format -> string |
| 41 | + |
| 42 | +(** ISO Base Media File Format, see RFC 6381 section 3.3. *) |
| 43 | +val iso_base_file_media_file_format : format -> string |
| 44 | + |
| 45 | +(** Proposed extension for files. *) |
| 46 | +val extension : format -> string |
| 47 | + |
| 48 | +(** Mime types *) |
| 49 | +val mime : format -> string |
| 50 | + |
| 51 | +(** Bitrate estimation in bits per second. *) |
| 52 | +val bitrate : format -> int |
| 53 | + |
| 54 | +(** Encoders that can output to a file. *) |
| 55 | +val file_output : format -> bool |
| 56 | + |
| 57 | +val with_file_output : format -> string -> format |
| 58 | + |
| 59 | +(** Encoders that can output to a arbitrary url. *) |
| 60 | +val url_output : format -> bool |
| 61 | + |
| 62 | +val with_url_output : format -> string -> format |
| 63 | + |
| 64 | +(** An encoder, once initialized, is something that consumes |
| 65 | + * frames, insert metadata and that you eventually close |
| 66 | + * (triggers flushing). |
| 67 | + * Insert metadata is really meant for inline metadata, i.e. |
| 68 | + * in most cases, stream sources. Otherwise, metadata are |
| 69 | + * passed when creating the encoder. For instance, the mp3 |
| 70 | + * encoder may accept metadata initally and write them as |
| 71 | + * id3 tags but does not support inline metadata. |
| 72 | + * Also, the ogg encoder supports inline metadata but restarts |
| 73 | + * its stream. This is ok, though, because the ogg container/streams |
| 74 | + * is meant to be sequentialized but not the mp3 format. |
| 75 | + * header contains data that should be sent first to streaming |
| 76 | + * client. *) |
| 77 | + |
| 78 | +type split_result = |
| 79 | + [ (* Returns (flushed, first_bytes_for_next_segment) *) |
| 80 | + `Ok of |
| 81 | + Strings.t * Strings.t |
| 82 | + | `Nope of Strings.t ] |
| 83 | + |
| 84 | +type hls = { |
| 85 | + (* Returns (init_segment, first_bytes) *) |
| 86 | + init_encode : Frame.t -> int -> int -> Strings.t option * Strings.t; |
| 87 | + split_encode : Frame.t -> int -> int -> split_result; |
| 88 | +} |
| 89 | + |
| 90 | +type encoder = { |
| 91 | + insert_metadata : Meta_format.export_metadata -> unit; |
| 92 | + (* Encoder are all called from the main |
| 93 | + * thread so there's no need to protect this |
| 94 | + * value with a mutex so far.. *) |
| 95 | + mutable header : Strings.t; |
| 96 | + hls : hls; |
| 97 | + encode : Frame.t -> int -> int -> Strings.t; |
| 98 | + stop : unit -> Strings.t; |
| 99 | +} |
| 100 | + |
| 101 | +type factory = string -> Meta_format.export_metadata -> encoder |
| 102 | + |
| 103 | +(** A plugin might or might not accept a given format. |
| 104 | + * If it accepts it, it gives a function creating suitable encoders. *) |
| 105 | +type plugin = format -> factory option |
| 106 | + |
| 107 | +val plug : plugin Plug.plug |
| 108 | + |
| 109 | +(** Return the first available encoder factory for that format. *) |
| 110 | +val get_factory : format -> factory |
0 commit comments