2009-05-01 09:31:59 -04:00
|
|
|
|
|
|
|
#ifndef __TRANSCODE_H__
|
|
|
|
#define __TRANSCODE_H__
|
|
|
|
|
2015-10-09 17:58:27 -04:00
|
|
|
#include <event2/buffer.h>
|
|
|
|
#include "db.h"
|
2015-03-20 18:40:42 -04:00
|
|
|
#include "http.h"
|
2019-04-02 16:47:11 -04:00
|
|
|
#include "misc.h"
|
2009-05-01 09:31:59 -04:00
|
|
|
|
2015-10-09 17:58:27 -04:00
|
|
|
enum transcode_profile
|
|
|
|
{
|
2019-02-08 12:53:40 -05:00
|
|
|
// Used for errors
|
|
|
|
XCODE_UNKNOWN = 0,
|
2019-01-11 13:34:36 -05:00
|
|
|
// Decodes the best audio stream into PCM16 or PCM24, no resampling (does not add wav header)
|
|
|
|
XCODE_PCM_NATIVE,
|
2019-04-02 16:47:11 -04:00
|
|
|
// Decodes/resamples the best audio stream into PCM16 (with wav header)
|
2019-02-08 12:53:40 -05:00
|
|
|
XCODE_PCM16_HEADER,
|
2019-04-02 16:47:11 -04:00
|
|
|
// Decodes/resamples the best audio stream into PCM16/24/32 (no wav headers)
|
|
|
|
XCODE_PCM16,
|
|
|
|
XCODE_PCM24,
|
|
|
|
XCODE_PCM32,
|
2021-03-28 14:00:15 -04:00
|
|
|
// Transcodes the best audio stream to MP3
|
2017-02-26 09:32:37 -05:00
|
|
|
XCODE_MP3,
|
2021-03-28 14:00:15 -04:00
|
|
|
// Transcodes the best audio stream to OPUS
|
2019-01-10 04:52:56 -05:00
|
|
|
XCODE_OPUS,
|
2021-03-28 14:00:15 -04:00
|
|
|
// Transcodes the best audio stream to ALAC
|
2021-01-17 16:45:24 -05:00
|
|
|
XCODE_ALAC,
|
2021-03-28 14:00:15 -04:00
|
|
|
// Transcodes the best audio stream from OGG
|
|
|
|
XCODE_OGG,
|
|
|
|
// Transcodes the best video stream to JPEG/PNG/VP8
|
2017-02-26 09:32:37 -05:00
|
|
|
XCODE_JPEG,
|
|
|
|
XCODE_PNG,
|
2020-11-05 17:04:56 -05:00
|
|
|
XCODE_VP8,
|
2015-10-09 17:58:27 -04:00
|
|
|
};
|
|
|
|
|
2021-04-06 10:16:32 -04:00
|
|
|
enum transcode_seek_type
|
|
|
|
{
|
|
|
|
XCODE_SEEK_SIZE,
|
|
|
|
XCODE_SEEK_SET,
|
|
|
|
XCODE_SEEK_CUR,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef void transcode_frame;
|
|
|
|
typedef int64_t(*transcode_seekfn)(void *arg, int64_t offset, enum transcode_seek_type seek_type);
|
|
|
|
|
2015-10-09 17:58:27 -04:00
|
|
|
struct decode_ctx;
|
|
|
|
struct encode_ctx;
|
2019-01-11 13:34:36 -05:00
|
|
|
struct transcode_ctx
|
|
|
|
{
|
|
|
|
struct decode_ctx *decode_ctx;
|
|
|
|
struct encode_ctx *encode_ctx;
|
|
|
|
};
|
2009-05-01 09:31:59 -04:00
|
|
|
|
2021-04-06 10:16:32 -04:00
|
|
|
struct transcode_evbuf_io
|
|
|
|
{
|
|
|
|
struct evbuffer *evbuf;
|
|
|
|
|
|
|
|
// Set to null if no seek support required
|
|
|
|
transcode_seekfn seekfn;
|
|
|
|
void *seekfn_arg;
|
|
|
|
};
|
2019-01-10 04:52:56 -05:00
|
|
|
|
2015-10-09 17:58:27 -04:00
|
|
|
// Setting up
|
|
|
|
struct decode_ctx *
|
2021-04-06 10:16:32 -04:00
|
|
|
transcode_decode_setup(enum transcode_profile profile, struct media_quality *quality, enum data_kind data_kind, const char *path, struct transcode_evbuf_io *evbuf_io, uint32_t song_length);
|
2009-05-01 09:31:59 -04:00
|
|
|
|
2015-10-09 17:58:27 -04:00
|
|
|
struct encode_ctx *
|
2019-04-02 16:47:11 -04:00
|
|
|
transcode_encode_setup(enum transcode_profile profile, struct media_quality *quality, struct decode_ctx *src_ctx, off_t *est_size, int width, int height);
|
2010-04-04 06:34:28 -04:00
|
|
|
|
2015-10-09 17:58:27 -04:00
|
|
|
struct transcode_ctx *
|
2019-04-02 16:47:11 -04:00
|
|
|
transcode_setup(enum transcode_profile profile, struct media_quality *quality, enum data_kind data_kind, const char *path, uint32_t song_length, off_t *est_size);
|
2009-05-01 09:31:59 -04:00
|
|
|
|
2015-10-09 17:58:27 -04:00
|
|
|
struct decode_ctx *
|
2019-04-02 16:47:11 -04:00
|
|
|
transcode_decode_setup_raw(enum transcode_profile profile, struct media_quality *quality);
|
2009-05-01 09:31:59 -04:00
|
|
|
|
|
|
|
int
|
2014-08-22 18:02:01 -04:00
|
|
|
transcode_needed(const char *user_agent, const char *client_codecs, char *file_codectype);
|
2009-05-01 09:31:59 -04:00
|
|
|
|
2015-10-09 17:58:27 -04:00
|
|
|
// Cleaning up
|
|
|
|
void
|
2017-02-26 17:41:30 -05:00
|
|
|
transcode_decode_cleanup(struct decode_ctx **ctx);
|
2015-10-09 17:58:27 -04:00
|
|
|
|
|
|
|
void
|
2017-02-26 17:41:30 -05:00
|
|
|
transcode_encode_cleanup(struct encode_ctx **ctx);
|
2015-10-09 17:58:27 -04:00
|
|
|
|
2015-03-14 16:42:53 -04:00
|
|
|
void
|
2017-02-26 17:41:30 -05:00
|
|
|
transcode_cleanup(struct transcode_ctx **ctx);
|
2015-03-14 16:42:53 -04:00
|
|
|
|
2015-10-09 17:58:27 -04:00
|
|
|
// Transcoding
|
|
|
|
|
2015-10-22 16:09:19 -04:00
|
|
|
/* Demuxes and decodes the next packet from the input.
|
|
|
|
*
|
2017-02-28 17:06:01 -05:00
|
|
|
* @out frame A pointer to the frame. Caller should not free it, that will
|
|
|
|
* be done by the next call to the function or by the cleanup
|
|
|
|
* function.
|
2017-02-26 17:41:30 -05:00
|
|
|
* @in ctx Decode context
|
|
|
|
* @return Positive if OK, negative if error, 0 if EOF
|
2015-10-22 16:09:19 -04:00
|
|
|
*/
|
|
|
|
int
|
2019-01-10 04:52:56 -05:00
|
|
|
transcode_decode(transcode_frame **frame, struct decode_ctx *ctx);
|
2015-10-22 16:09:19 -04:00
|
|
|
|
|
|
|
/* Encodes and remuxes a frame. Also resamples if needed.
|
|
|
|
*
|
2017-02-26 17:41:30 -05:00
|
|
|
* @out evbuf An evbuffer filled with remuxed data
|
|
|
|
* @in ctx Encode context
|
2017-02-28 17:06:01 -05:00
|
|
|
* @in frame The decoded frame to encode, e.g. from transcode_decode
|
|
|
|
* @in eof If true the muxer will write a trailer to the output
|
2017-02-26 17:41:30 -05:00
|
|
|
* @return Bytes added if OK, negative if error
|
2015-10-22 16:09:19 -04:00
|
|
|
*/
|
2015-10-09 17:58:27 -04:00
|
|
|
int
|
2019-01-10 04:52:56 -05:00
|
|
|
transcode_encode(struct evbuffer *evbuf, struct encode_ctx *ctx, transcode_frame *frame, int eof);
|
2015-10-09 17:58:27 -04:00
|
|
|
|
2017-02-26 17:41:30 -05:00
|
|
|
/* Demuxes, decodes, encodes and remuxes from the input.
|
2015-10-22 16:09:19 -04:00
|
|
|
*
|
2017-02-26 17:41:30 -05:00
|
|
|
* @out evbuf An evbuffer filled with remuxed data
|
2017-02-28 17:06:01 -05:00
|
|
|
* @out icy_timer True if METADATA_ICY_INTERVAL has elapsed
|
|
|
|
* @in ctx Transcode context
|
2017-02-26 17:41:30 -05:00
|
|
|
* @in want_bytes Minimum number of bytes the caller wants added to the evbuffer
|
|
|
|
* - set want_bytes to 0 to transcode everything until EOF/error
|
|
|
|
* - set want_bytes to 1 to get one encoded packet
|
|
|
|
* @return Bytes added if OK, negative if error, 0 if EOF
|
2015-10-22 16:09:19 -04:00
|
|
|
*/
|
2015-10-09 17:58:27 -04:00
|
|
|
int
|
2017-02-28 17:06:01 -05:00
|
|
|
transcode(struct evbuffer *evbuf, int *icy_timer, struct transcode_ctx *ctx, int want_bytes);
|
2015-10-09 17:58:27 -04:00
|
|
|
|
2017-02-28 17:06:01 -05:00
|
|
|
/* Converts a buffer with raw data to a frame that can be passed directly to the
|
2019-01-10 04:52:56 -05:00
|
|
|
* transcode_encode() function. It does not copy, so if you free the data the
|
|
|
|
* frame will become invalid.
|
2017-02-28 17:06:01 -05:00
|
|
|
*
|
|
|
|
* @in data Buffer with raw data
|
|
|
|
* @in size Size of buffer
|
2019-02-08 12:53:40 -05:00
|
|
|
* @in nsamples Number of samples in the buffer
|
2019-04-02 16:47:11 -04:00
|
|
|
* @in quality Sample rate, bits per sample and channels
|
2017-02-28 17:06:01 -05:00
|
|
|
* @return Opaque pointer to frame if OK, otherwise NULL
|
|
|
|
*/
|
2019-01-10 04:52:56 -05:00
|
|
|
transcode_frame *
|
2019-04-02 16:47:11 -04:00
|
|
|
transcode_frame_new(void *data, size_t size, int nsamples, struct media_quality *quality);
|
2017-02-28 17:06:01 -05:00
|
|
|
void
|
2019-01-10 04:52:56 -05:00
|
|
|
transcode_frame_free(transcode_frame *frame);
|
2015-10-09 17:58:27 -04:00
|
|
|
|
2017-02-28 17:06:01 -05:00
|
|
|
/* Seek to the specified position - next transcode() will return this packet
|
|
|
|
*
|
|
|
|
* @in ctx Transcode context
|
|
|
|
* @in seek Requested seek position in ms
|
|
|
|
* @return Negative if error, otherwise actual seek position
|
|
|
|
*/
|
2015-10-09 17:58:27 -04:00
|
|
|
int
|
|
|
|
transcode_seek(struct transcode_ctx *ctx, int ms);
|
|
|
|
|
2017-02-28 17:06:01 -05:00
|
|
|
/* Query for information about a media file opened by transcode_decode_setup()
|
|
|
|
*
|
|
|
|
* @in ctx Decode context
|
|
|
|
* @in query Query - see implementation for supported queries
|
|
|
|
* @return Negative if error, otherwise query dependent
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
transcode_decode_query(struct decode_ctx *ctx, const char *query);
|
|
|
|
|
2019-01-11 13:34:36 -05:00
|
|
|
/* Query for information (e.g. sample rate) about the output being produced by
|
|
|
|
* the transcoding
|
|
|
|
*
|
|
|
|
* @in ctx Encode context
|
|
|
|
* @in query Query - see implementation for supported queries
|
|
|
|
* @return Negative if error, otherwise query dependent
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
transcode_encode_query(struct encode_ctx *ctx, const char *query);
|
|
|
|
|
2015-10-09 17:58:27 -04:00
|
|
|
// Metadata
|
|
|
|
struct http_icy_metadata *
|
|
|
|
transcode_metadata(struct transcode_ctx *ctx, int *changed);
|
|
|
|
|
2009-05-01 09:31:59 -04:00
|
|
|
#endif /* !__TRANSCODE_H__ */
|