Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mkvmux: handle COMMENT tag in metadata, fixes #2511, fixes #2510
  • Loading branch information
perexg committed Nov 30, 2014
1 parent 8c743ba commit bd20a53
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/dvr/dvr_rec.c
Expand Up @@ -359,7 +359,7 @@ dvr_rec_start(dvr_entry_t *de, const streaming_start_t *ss)
}

if(cfg->dvr_tag_files && de->de_bcast) {
if(muxer_write_meta(muxer, de->de_bcast)) {
if(muxer_write_meta(muxer, de->de_bcast, de->de_comment)) {
dvr_rec_fatal_error(de, "Unable to write meta data");
return -1;
}
Expand Down
7 changes: 4 additions & 3 deletions src/muxer.h
Expand Up @@ -79,7 +79,8 @@ typedef struct muxer {
const struct streaming_start *); // stream changes
int (*m_close) (struct muxer *); // Close the muxer
void (*m_destroy) (struct muxer *); // Free the memory
int (*m_write_meta) (struct muxer *, struct epg_broadcast *); // Append epg data
int (*m_write_meta) (struct muxer *, struct epg_broadcast *,
const char *comment); // Append epg data
int (*m_write_pkt) (struct muxer *, // Append a media packet
streaming_message_type_t,
void *);
Expand Down Expand Up @@ -127,8 +128,8 @@ static inline int muxer_close (muxer_t *m)
static inline int muxer_destroy (muxer_t *m)
{ if (m) { m->m_destroy(m); return 0; } return -1; }

static inline int muxer_write_meta (muxer_t *m, struct epg_broadcast *eb)
{ if (m && eb) return m->m_write_meta(m, eb); return -1; }
static inline int muxer_write_meta (muxer_t *m, struct epg_broadcast *eb, const char *comment)
{ if (m && eb) return m->m_write_meta(m, eb, comment); return -1; }

static inline int muxer_write_pkt (muxer_t *m, streaming_message_type_t smt, void *data)
{ if (m && data) return m->m_write_pkt(m, smt, data); return -1; }
Expand Down
2 changes: 1 addition & 1 deletion src/muxer/muxer_libav.c
Expand Up @@ -464,7 +464,7 @@ lav_muxer_write_pkt(muxer_t *m, streaming_message_type_t smt, void *data)
* NOP
*/
static int
lav_muxer_write_meta(muxer_t *m, struct epg_broadcast *eb)
lav_muxer_write_meta(muxer_t *m, struct epg_broadcast *eb, const char *comment)
{
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/muxer/muxer_pass.c
Expand Up @@ -514,7 +514,7 @@ pass_muxer_write_pkt(muxer_t *m, streaming_message_type_t smt, void *data)
* NOP
*/
static int
pass_muxer_write_meta(muxer_t *m, struct epg_broadcast *eb)
pass_muxer_write_meta(muxer_t *m, struct epg_broadcast *eb, const char *comment)
{
return 0;
}
Expand Down
5 changes: 3 additions & 2 deletions src/muxer/muxer_tvh.c
Expand Up @@ -174,11 +174,12 @@ tvh_muxer_write_pkt(muxer_t *m, streaming_message_type_t smt, void *data)
* Append meta data when a channel changes its programme
*/
static int
tvh_muxer_write_meta(muxer_t *m, struct epg_broadcast *eb)
tvh_muxer_write_meta(muxer_t *m, struct epg_broadcast *eb,
const char *comment)
{
tvh_muxer_t *tm = (tvh_muxer_t*)m;

if(mk_mux_write_meta(tm->tm_ref, NULL, eb)) {
if(mk_mux_write_meta(tm->tm_ref, NULL, eb, comment)) {
tm->m_errors++;
return -1;
}
Expand Down
20 changes: 17 additions & 3 deletions src/muxer/tvh/mkmux.c
Expand Up @@ -32,6 +32,7 @@
#include "dvr/dvr.h"
#include "mkmux.h"
#include "ebml.h"
#include "lang_codes.h"
#include "parsers/parser_avc.h"

extern int dvr_iov_max;
Expand Down Expand Up @@ -669,7 +670,8 @@ addtag(htsbuf_queue_t *q, htsbuf_queue_t *t)
*
*/
static htsbuf_queue_t *
_mk_build_metadata(const dvr_entry_t *de, const epg_broadcast_t *ebc)
_mk_build_metadata(const dvr_entry_t *de, const epg_broadcast_t *ebc,
const char *comment)
{
htsbuf_queue_t *q = htsbuf_queue_alloc(0);
char datestr[64], ctype[100];
Expand All @@ -680,6 +682,7 @@ _mk_build_metadata(const dvr_entry_t *de, const epg_broadcast_t *ebc)
epg_episode_t *ee = NULL;
channel_t *ch = NULL;
lang_str_t *ls = NULL;
const char **langs, *lang;

if (ebc) ee = ebc->episode;
else if (de && de->de_bcast) ee = de->de_bcast->episode;
Expand Down Expand Up @@ -747,6 +750,16 @@ _mk_build_metadata(const dvr_entry_t *de, const epg_broadcast_t *ebc)
num.text, NULL, 0, NULL));
}

if (comment) {
lang = "eng";
if ((langs = lang_code_split(NULL))) {
lang = tvh_strdupa(langs[0]);
free(langs);
}

addtag(q, build_tag_string("COMMENT", comment, lang, 0, NULL));
}

return q;
}

Expand Down Expand Up @@ -1212,15 +1225,16 @@ mk_mux_write_pkt(mk_mux_t *mkm, th_pkt_t *pkt)
*/
int
mk_mux_write_meta(mk_mux_t *mkm, const dvr_entry_t *de,
const epg_broadcast_t *ebc)
const epg_broadcast_t *ebc,
const char *comment)
{
htsbuf_queue_t q;

if(!mkm->metadata_pos)
mkm->metadata_pos = mkm->fdpos;

htsbuf_queue_init(&q, 0);
ebml_append_master(&q, 0x1254c367, _mk_build_metadata(de, ebc));
ebml_append_master(&q, 0x1254c367, _mk_build_metadata(de, ebc, comment));
mk_write_queue(mkm, &q);

return mkm->error;
Expand Down
3 changes: 2 additions & 1 deletion src/muxer/tvh/mkmux.h
Expand Up @@ -38,7 +38,8 @@ int mk_mux_init(mk_mux_t *mkm, const char *title,

int mk_mux_write_pkt (mk_mux_t *mkm, struct th_pkt *pkt);
int mk_mux_write_meta(mk_mux_t *mkm, const struct dvr_entry *de,
const struct epg_broadcast *eb);
const struct epg_broadcast *eb,
const char *comment);

int mk_mux_insert_chapter(mk_mux_t *mkm);

Expand Down

0 comments on commit bd20a53

Please sign in to comment.