mirror of https://git.ffmpeg.org/ffmpeg.git
avcodec/movtextenc: fix writing to bytestream on BE arches
Fixes fate-binsub-movtextenc on PPC64 Currently tags are written in reverse order on BE arches. This is fixed by using MKBETAG() and AV_RB32() to be arch agnostics. Also s->font_count is of type int. On BE arches with 32bit int, count = AV_RB16(&s->font_count) will read two most significant bytes instead of the least significant bytes. This is fixed by assigning s->font_count to count first. The final change is modifying the type of len. On BE arches the most significant byte of the int was written instead of the least significant byte. Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
This commit is contained in:
parent
8e58db7348
commit
d4c46dc328
|
@ -116,6 +116,7 @@ static void encode_styl(MovTextContext *s, uint32_t tsmb_type)
|
||||||
if ((s->box_flags & STYL_BOX) && s->count) {
|
if ((s->box_flags & STYL_BOX) && s->count) {
|
||||||
tsmb_size = s->count * STYLE_RECORD_SIZE + SIZE_ADD;
|
tsmb_size = s->count * STYLE_RECORD_SIZE + SIZE_ADD;
|
||||||
tsmb_size = AV_RB32(&tsmb_size);
|
tsmb_size = AV_RB32(&tsmb_size);
|
||||||
|
tsmb_type = AV_RB32(&tsmb_type);
|
||||||
style_entries = AV_RB16(&s->count);
|
style_entries = AV_RB16(&s->count);
|
||||||
/*The above three attributes are hard coded for now
|
/*The above three attributes are hard coded for now
|
||||||
but will come from ASS style in the future*/
|
but will come from ASS style in the future*/
|
||||||
|
@ -149,6 +150,7 @@ static void encode_hlit(MovTextContext *s, uint32_t tsmb_type)
|
||||||
if (s->box_flags & HLIT_BOX) {
|
if (s->box_flags & HLIT_BOX) {
|
||||||
tsmb_size = 12;
|
tsmb_size = 12;
|
||||||
tsmb_size = AV_RB32(&tsmb_size);
|
tsmb_size = AV_RB32(&tsmb_size);
|
||||||
|
tsmb_type = AV_RB32(&tsmb_type);
|
||||||
start = AV_RB16(&s->hlit.start);
|
start = AV_RB16(&s->hlit.start);
|
||||||
end = AV_RB16(&s->hlit.end);
|
end = AV_RB16(&s->hlit.end);
|
||||||
av_bprint_append_any(&s->buffer, &tsmb_size, 4);
|
av_bprint_append_any(&s->buffer, &tsmb_size, 4);
|
||||||
|
@ -164,6 +166,7 @@ static void encode_hclr(MovTextContext *s, uint32_t tsmb_type)
|
||||||
if (s->box_flags & HCLR_BOX) {
|
if (s->box_flags & HCLR_BOX) {
|
||||||
tsmb_size = 12;
|
tsmb_size = 12;
|
||||||
tsmb_size = AV_RB32(&tsmb_size);
|
tsmb_size = AV_RB32(&tsmb_size);
|
||||||
|
tsmb_type = AV_RB32(&tsmb_type);
|
||||||
color = AV_RB32(&s->hclr.color);
|
color = AV_RB32(&s->hclr.color);
|
||||||
av_bprint_append_any(&s->buffer, &tsmb_size, 4);
|
av_bprint_append_any(&s->buffer, &tsmb_size, 4);
|
||||||
av_bprint_append_any(&s->buffer, &tsmb_type, 4);
|
av_bprint_append_any(&s->buffer, &tsmb_type, 4);
|
||||||
|
@ -172,9 +175,9 @@ static void encode_hclr(MovTextContext *s, uint32_t tsmb_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Box box_types[] = {
|
static const Box box_types[] = {
|
||||||
{ MKTAG('s','t','y','l'), encode_styl },
|
{ MKBETAG('s','t','y','l'), encode_styl },
|
||||||
{ MKTAG('h','l','i','t'), encode_hlit },
|
{ MKBETAG('h','l','i','t'), encode_hlit },
|
||||||
{ MKTAG('h','c','l','r'), encode_hclr },
|
{ MKBETAG('h','c','l','r'), encode_hclr },
|
||||||
};
|
};
|
||||||
|
|
||||||
const static size_t box_count = FF_ARRAY_ELEMS(box_types);
|
const static size_t box_count = FF_ARRAY_ELEMS(box_types);
|
||||||
|
@ -316,14 +319,16 @@ static int encode_sample_description(AVCodecContext *avctx)
|
||||||
// FontTableBox {
|
// FontTableBox {
|
||||||
tsmb_size = SIZE_ADD + 3 * s->font_count + font_names_total_len;
|
tsmb_size = SIZE_ADD + 3 * s->font_count + font_names_total_len;
|
||||||
tsmb_size = AV_RB32(&tsmb_size);
|
tsmb_size = AV_RB32(&tsmb_size);
|
||||||
tsmb_type = MKTAG('f','t','a','b');
|
tsmb_type = MKBETAG('f','t','a','b');
|
||||||
count = AV_RB16(&s->font_count);
|
tsmb_type = AV_RB32(&tsmb_type);
|
||||||
|
count = s->font_count;
|
||||||
|
count = AV_RB16(&count);
|
||||||
av_bprint_append_any(&s->buffer, &tsmb_size, 4);
|
av_bprint_append_any(&s->buffer, &tsmb_size, 4);
|
||||||
av_bprint_append_any(&s->buffer, &tsmb_type, 4);
|
av_bprint_append_any(&s->buffer, &tsmb_type, 4);
|
||||||
av_bprint_append_any(&s->buffer, &count, 2);
|
av_bprint_append_any(&s->buffer, &count, 2);
|
||||||
// FontRecord {
|
// FontRecord {
|
||||||
for (i = 0; i < s->font_count; i++) {
|
for (i = 0; i < s->font_count; i++) {
|
||||||
int len;
|
uint8_t len;
|
||||||
fontID = i + 1;
|
fontID = i + 1;
|
||||||
fontID = AV_RB16(&fontID);
|
fontID = AV_RB16(&fontID);
|
||||||
av_bprint_append_any(&s->buffer, &fontID, 2);
|
av_bprint_append_any(&s->buffer, &fontID, 2);
|
||||||
|
|
Loading…
Reference in New Issue