hmmlib: add custom attributes

This commit is contained in:
Alex Baines 2018-02-21 20:05:03 +00:00
parent c7762a0f7d
commit bbd1d657a7
2 changed files with 27 additions and 3 deletions

View File

@ -7,6 +7,8 @@
// Data structures // Data structures
#define HMML_CUSTOM_ATTR_COUNT 16
typedef struct { typedef struct {
char* member; char* member;
char* stream_platform; char* stream_platform;
@ -28,6 +30,8 @@ typedef struct {
char* template; char* template;
char* medium; char* medium;
char* custom[HMML_CUSTOM_ATTR_COUNT];
} HMML_VideoMetaData; } HMML_VideoMetaData;
typedef struct { typedef struct {

View File

@ -5,7 +5,7 @@
#include "stb_sb.h" #include "stb_sb.h"
#include "hmmlib.h" #include "hmmlib.h"
const struct HMML_Version hmml_version = { 0, 2, 0 }; const struct HMML_Version hmml_version = { 0, 3, 0 };
typedef struct { typedef struct {
int line; int line;
@ -80,7 +80,7 @@
S [\t \r]* S [\t \r]*
ATTR_SIMPLE [^\" \]\t\r\n][^ \]\t\r\n]* ATTR_SIMPLE [^\" \]\t\r\n][^ \]\t\r\n]*
ATTR_ALNUM [0-9a-zA-Z][0-9a-zA-Z_]* ATTR_ALNUM [0-9a-zA-Z][0-9a-zA-Z_]*
ATTR_QUOTED \"([^\n\"\\]|\\.)*\" ATTR_QUOTED \"([^\"\\]|\\.)*\"
TAG_VIDEO_OPEN \[video TAG_VIDEO_OPEN \[video
TIMECODE \[[0-9]{1,2}(:[0-5][0-9]){1,2}\] TIMECODE \[[0-9]{1,2}(:[0-5][0-9]){1,2}\]
BAD_TIMECODE \[[0-9]{1,2}(:[6-9][0-9]){1,2}\] BAD_TIMECODE \[[0-9]{1,2}(:[6-9][0-9]){1,2}\]
@ -121,11 +121,27 @@ RB \]
<VIDEO>id{S}= { yyextra->attr = V_(id); BEGIN(V_ATTR); } <VIDEO>id{S}= { yyextra->attr = V_(id); BEGIN(V_ATTR); }
<VIDEO>template{S}= { yyextra->attr = V_(template); BEGIN(V_ATTR); } <VIDEO>template{S}= { yyextra->attr = V_(template); BEGIN(V_ATTR); }
<VIDEO>medium{S}= { yyextra->attr = V_(medium); BEGIN(V_ATTR); } <VIDEO>medium{S}= { yyextra->attr = V_(medium); BEGIN(V_ATTR); }
<VIDEO>custom0{S}= { yyextra->attr = V_(custom[0]); BEGIN(V_ATTR); } // probably smarter way to do this ¯\_(ツ)_/¯
<VIDEO>custom1{S}= { yyextra->attr = V_(custom[1]); BEGIN(V_ATTR); }
<VIDEO>custom2{S}= { yyextra->attr = V_(custom[2]); BEGIN(V_ATTR); }
<VIDEO>custom3{S}= { yyextra->attr = V_(custom[3]); BEGIN(V_ATTR); }
<VIDEO>custom4{S}= { yyextra->attr = V_(custom[4]); BEGIN(V_ATTR); }
<VIDEO>custom5{S}= { yyextra->attr = V_(custom[5]); BEGIN(V_ATTR); }
<VIDEO>custom6{S}= { yyextra->attr = V_(custom[6]); BEGIN(V_ATTR); }
<VIDEO>custom7{S}= { yyextra->attr = V_(custom[7]); BEGIN(V_ATTR); }
<VIDEO>custom8{S}= { yyextra->attr = V_(custom[8]); BEGIN(V_ATTR); }
<VIDEO>custom9{S}= { yyextra->attr = V_(custom[9]); BEGIN(V_ATTR); }
<VIDEO>custom10{S}= { yyextra->attr = V_(custom[10]); BEGIN(V_ATTR); }
<VIDEO>custom11{S}= { yyextra->attr = V_(custom[11]); BEGIN(V_ATTR); }
<VIDEO>custom12{S}= { yyextra->attr = V_(custom[12]); BEGIN(V_ATTR); }
<VIDEO>custom13{S}= { yyextra->attr = V_(custom[13]); BEGIN(V_ATTR); }
<VIDEO>custom14{S}= { yyextra->attr = V_(custom[14]); BEGIN(V_ATTR); }
<VIDEO>custom15{S}= { yyextra->attr = V_(custom[15]); BEGIN(V_ATTR); }
<VIDEO>co\-host{S}= { yyextra->attr = V_(co_hosts); BEGIN(V2_ATTR); } <VIDEO>co\-host{S}= { yyextra->attr = V_(co_hosts); BEGIN(V2_ATTR); }
<VIDEO>guest{S}= { yyextra->attr = V_(guests); BEGIN(V2_ATTR); } <VIDEO>guest{S}= { yyextra->attr = V_(guests); BEGIN(V2_ATTR); }
<VIDEO>annotator{S}= { yyextra->attr = V_(annotators); BEGIN(V2_ATTR); } <VIDEO>annotator{S}= { yyextra->attr = V_(annotators); BEGIN(V2_ATTR); }
<VIDEO>\] { BEGIN(ANNOTATION); }; <VIDEO>\] { BEGIN(ANNOTATION); };
<VIDEO>. { HMML_ERR("Invalid char '%s' in video tag.", yytext); } <VIDEO>. { HMML_ERR("Unknown attribute in video tag, beginning with '%s'.", yytext); }
<V_ATTR>{S} { BEGIN(VIDEO); } <V_ATTR>{S} { BEGIN(VIDEO); }
<V_ATTR>{ATTR_SIMPLE} { *(char**)yyextra->attr = strndup(yytext , yyleng ); BEGIN(VIDEO); } <V_ATTR>{ATTR_SIMPLE} { *(char**)yyextra->attr = strndup(yytext , yyleng ); BEGIN(VIDEO); }
@ -325,6 +341,10 @@ void hmml_free(HMML_Output* hmml){
free(hmml->metadata.template); free(hmml->metadata.template);
free(hmml->metadata.medium); free(hmml->metadata.medium);
for(size_t i = 0; i < HMML_CUSTOM_ATTR_COUNT; ++i){
free(hmml->metadata.custom[i]);
}
sb_each(i, hmml->metadata.co_hosts) free(*i); sb_each(i, hmml->metadata.co_hosts) free(*i);
sb_each(i, hmml->metadata.guests) free(*i); sb_each(i, hmml->metadata.guests) free(*i);
sb_each(i, hmml->metadata.annotators) free(*i); sb_each(i, hmml->metadata.annotators) free(*i);