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"
|
2009-05-01 09:31:59 -04:00
|
|
|
|
2015-10-09 17:58:27 -04:00
|
|
|
enum transcode_profile
|
|
|
|
{
|
2017-02-26 09:32:37 -05:00
|
|
|
// Transcodes the best audio stream into PCM16 (does not add wav header)
|
|
|
|
XCODE_PCM16_NOHEADER,
|
|
|
|
// Transcodes the best audio stream into PCM16 (with wav header)
|
|
|
|
XCODE_PCM16_HEADER,
|
|
|
|
// Transcodes the best audio stream into MP3
|
|
|
|
XCODE_MP3,
|
|
|
|
// Transcodes the best video stream into JPEG/PNG
|
|
|
|
XCODE_JPEG,
|
|
|
|
XCODE_PNG,
|
2015-10-09 17:58:27 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct decode_ctx;
|
|
|
|
struct encode_ctx;
|
2009-05-01 09:31:59 -04:00
|
|
|
struct transcode_ctx;
|
2015-10-09 17:58:27 -04:00
|
|
|
struct decoded_frame;
|
2009-05-01 09:31:59 -04:00
|
|
|
|
2015-10-09 17:58:27 -04:00
|
|
|
// Setting up
|
|
|
|
struct decode_ctx *
|
2017-02-26 09:32:37 -05:00
|
|
|
transcode_decode_setup(enum transcode_profile profile, enum data_kind data_kind, const char *path, uint32_t song_length);
|
2009-05-01 09:31:59 -04:00
|
|
|
|
2015-10-09 17:58:27 -04:00
|
|
|
struct encode_ctx *
|
2017-02-26 09:32:37 -05:00
|
|
|
transcode_encode_setup(enum transcode_profile profile, struct decode_ctx *src_ctx, off_t *est_size);
|
2010-04-04 06:34:28 -04:00
|
|
|
|
2015-10-09 17:58:27 -04:00
|
|
|
struct transcode_ctx *
|
2017-02-26 09:32:37 -05:00
|
|
|
transcode_setup(enum transcode_profile profile, 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 *
|
|
|
|
transcode_decode_setup_raw(void);
|
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
|
|
|
|
|
|
|
void
|
2015-10-09 17:58:27 -04:00
|
|
|
transcode_decoded_free(struct decoded_frame *decoded);
|
|
|
|
|
|
|
|
// Transcoding
|
|
|
|
|
2015-10-22 16:09:19 -04:00
|
|
|
/* Demuxes and decodes the next packet from the input.
|
|
|
|
*
|
2017-02-26 17:41:30 -05:00
|
|
|
* @out decoded A newly allocated struct with a pointer to the frame and the
|
|
|
|
* stream. Must be freed with transcode_decoded_free().
|
|
|
|
* @in ctx Decode context
|
|
|
|
* @return Positive if OK, negative if error, 0 if EOF
|
2015-10-22 16:09:19 -04:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
transcode_decode(struct decoded_frame **decoded, struct decode_ctx *ctx);
|
|
|
|
|
|
|
|
/* 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 frame The frame to encode, e.g. from transcode_decode
|
|
|
|
* @in ctx Encode context
|
|
|
|
* @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
|
|
|
|
transcode_encode(struct evbuffer *evbuf, struct decoded_frame *decoded, struct encode_ctx *ctx);
|
|
|
|
|
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
|
|
|
|
* @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
|
|
|
|
* @in ctx Transcode context
|
|
|
|
* @out icy_timer True if METADATA_ICY_INTERVAL has elapsed
|
|
|
|
* @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-26 17:41:30 -05:00
|
|
|
transcode(struct evbuffer *evbuf, int want_bytes, struct transcode_ctx *ctx, int *icy_timer);
|
2015-10-09 17:58:27 -04:00
|
|
|
|
|
|
|
struct decoded_frame *
|
|
|
|
transcode_raw2frame(uint8_t *data, size_t size);
|
|
|
|
|
|
|
|
// Seeking
|
|
|
|
int
|
|
|
|
transcode_seek(struct transcode_ctx *ctx, int ms);
|
|
|
|
|
|
|
|
// Metadata
|
|
|
|
struct http_icy_metadata *
|
|
|
|
transcode_metadata(struct transcode_ctx *ctx, int *changed);
|
|
|
|
|
2009-05-01 09:31:59 -04:00
|
|
|
#endif /* !__TRANSCODE_H__ */
|