On Wed, Jun 17, 2015 at 08:43:26PM +0530, Niklesh Lalwani wrote:
> From: Niklesh <niklesh.lalw...@iitb.ac.in>
> 
> Support for Bold, Italic and Underlined styles. The style information is 
> appended into the buffer after the text. Dynarray is used to account for 
> multiple style records. Tested on QuickTime OSX and iPhone.
> Signed-off-by: Niklesh <niklesh.lalw...@iitb.ac.in>
> ---
>  libavcodec/movtextenc.c | 165 
> ++++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 145 insertions(+), 20 deletions(-)
> 
> diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c
> index 1b8f454..56c599d 100644
> --- a/libavcodec/movtextenc.c
> +++ b/libavcodec/movtextenc.c
> @@ -24,14 +24,38 @@
>  #include "libavutil/avassert.h"
>  #include "libavutil/avstring.h"
>  #include "libavutil/intreadwrite.h"
> +#include "libavutil/mem.h"
> +#include "libavutil/common.h"
>  #include "ass_split.h"
>  #include "ass.h"
>  

> +#define STYLE_FLAG_BOLD         1
> +#define STYLE_FLAG_ITALIC       2
> +#define STYLE_FLAG_UNDERLINE    4

#define STYLE_FLAG_BOLD      (1<<0)
#define STYLE_FLAG_ITALIC    (1<<1)
#define STYLE_FLAG_UNDERLINE (1<<2)

it's more obvious they are combinable flags that way, and you can see when
you reach a 8, 16, 32 or whatever boundary.

> +#define STYLE_RECORD_SIZE       12
> +#define SIZE_ADD                10
> +
> +
> +typedef struct {
> +    uint16_t style_start;
> +    uint16_t style_end;
> +    uint8_t style_flag;
> +} StyleBox;
> +
>  typedef struct {
>      ASSSplitContext *ass_ctx;
> -    char buffer[2048];
> -    char *ptr;
> -    char *end;
> +    AVBPrint buffer;
> +    StyleBox **style_attributes;
> +    StyleBox *style_attributes_temp;
> +    int count;
> +    uint8_t style_box_flag;
> +    uint32_t tsmb_size;
> +    uint32_t tsmb_type;
> +    uint16_t style_entries;
> +    uint16_t style_fontID;
> +    uint8_t style_fontsize;
> +    uint32_t style_color;
> +    uint16_t text_pos;
>  } MovTextContext;
>  
>  
> @@ -79,32 +103,98 @@ static av_cold int mov_text_encode_init(AVCodecContext 
> *avctx)
>      if (!avctx->extradata)
>          return AVERROR(ENOMEM);
>  
> +    av_bprint_init(&s->buffer, 0, AV_BPRINT_SIZE_UNLIMITED);
> +
>      memcpy(avctx->extradata, text_sample_entry, avctx->extradata_size);
>  
>      s->ass_ctx = ff_ass_split(avctx->subtitle_header);
>      return s->ass_ctx ? 0 : AVERROR_INVALIDDATA;
>  }
>  
> +static void mov_text_style_cb(void *priv, const char style, int close)
> +{
> +    MovTextContext *s = priv;
> +    if (!close) {
> +        if (s->style_box_flag == 0) {   //first style entry
> +
> +            s->style_attributes_temp = av_malloc(sizeof(StyleBox));

sizeof(*s->style_attributes_temp)

> +            if (!s->style_attributes_temp)
> +                return AVERROR(ENOMEM);
> +
> +            s->style_attributes_temp->style_flag = 0;

> +            s->style_attributes_temp->style_start = AV_RB16(&s->text_pos);

there is no risk of alignement constraints that wouldn't be honored here,
right?

[...]
> -    if (s->ptr == s->buffer)
> -        return 0;
> -

> -    AV_WB16(buf, strlen(s->buffer));
> +    AV_WB16(buf, s->text_pos);

Any risk of having a len too large? Maybe you should initialize the
AVBuffer with a max limit size.

[...]

No other comment from me.

-- 
Clément B.

Attachment: pgp2YN0b4fFOW.pgp
Description: PGP signature

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to