On Wed, Oct 09, 2013 at 03:03:26PM +0300, Martin Storsjö wrote:
> --- /dev/null
> +++ b/libavformat/hdsenc.c
> @@ -0,0 +1,586 @@
> +
> +typedef struct {
> +} Fragment;
> +
> +typedef struct {
> +} OutputStream;
> +
> +typedef struct {
> +} HDSContext;
I suggest always avoiding anonymous structs. We've only had problems
with them in headers so far, but they get moved around and people look
at the .c files for examples.
> +static int parse_header(OutputStream *os, const uint8_t *buf, int buf_size)
> +{
> + if (buf_size < 13)
> + return AVERROR_INVALIDDATA;
> + if (memcmp(buf, "FLV", 3))
> + return AVERROR_INVALIDDATA;
> + buf += 13;
> + buf_size -= 13;
> + while (buf_size >= 11 + 4) {
> + int type = buf[0];
> + int size = AV_RB24(&buf[1]) + 11 + 4;
> + if (size > buf_size)
> + return AVERROR_INVALIDDATA;
> + if (type == 8 || type == 9) {
> + if (os->nb_extra_packets > FF_ARRAY_ELEMS(os->extra_packets))
> + return AVERROR_INVALIDDATA;
> + os->extra_packet_sizes[os->nb_extra_packets] = size;
> + os->extra_packets[os->nb_extra_packets] = av_malloc(size);
> + if (!os->extra_packets[os->nb_extra_packets])
> + return AVERROR(ENOMEM);
> + memcpy(os->extra_packets[os->nb_extra_packets], buf, size);
> + os->nb_extra_packets++;
> + } else if (type == 0x12) {
> + if (os->metadata)
> + return AVERROR_INVALIDDATA;
> + os->metadata_size = size - 11 - 4;
> + os->metadata = av_malloc(os->metadata_size);
> + if (!os->metadata)
> + return AVERROR(ENOMEM);
> + memcpy(os->metadata, buf + 11, os->metadata_size);
> + }
> + buf += size;
> + buf_size -= size;
nit: some lines could be aligned
> +static int add_fragment(OutputStream *os, const char *file,
> + int64_t start_time, int64_t duration)
> +{
> + Fragment *frag;
> + if (duration == 0)
> + duration = 1;
> + if (os->nb_fragments >= os->fragments_size) {
> + int ret;
> + os->fragments_size = (os->fragments_size + 1) * 2;
> + if ((ret = av_reallocp_array(&os->fragments, os->fragments_size,
> + sizeof(*os->fragments))) < 0) {
> + os->fragments_size = 0;
> + os->nb_fragments = 0;
> + return ret;
> + }
> + }
> + frag = av_mallocz(sizeof(*frag));
> + if (!frag)
> + return AVERROR(ENOMEM);
> + av_strlcpy(frag->file, file, sizeof(frag->file));
> + frag->start_time = start_time;
> + frag->duration = duration;
> + frag->n = os->fragment_index;
> + os->fragments[os->nb_fragments++] = frag;
> + os->fragment_index++;
> + return 0;
> +}
nit: same
Diego
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel