ut0mt8 / nginx-rtmp-module

NGINX-based Media Streaming Server
http://nginx-rtmp.blogspot.com
BSD 2-Clause "Simplified" License
86 stars 32 forks source link

Dash manifest with repetition : #10

Closed ut0mt8 closed 6 years ago

ut0mt8 commented 6 years ago
static u_char *
ngx_rtmp_dash_write_segment(u_char *p, u_char *last, ngx_uint_t t, ngx_uint_t d, ngx_uint_t r)
{
#define NGX_RTMP_DASH_MANIFEST_TIME                                            \
    "             <S t=\"%uD\" d=\"%uD\"/>\n"

#define NGX_RTMP_DASH_MANIFEST_TIME_WITH_REPETITION                            \
    "             <S t=\"%uD\" d=\"%uD\" r=\"%uD\"/>\n"

    if (r == 0) {
        p = ngx_slprintf(p, last, NGX_RTMP_DASH_MANIFEST_TIME,
                         t, d);
    } else {
        p = ngx_slprintf(p, last, NGX_RTMP_DASH_MANIFEST_TIME_WITH_REPETITION,
                         t, d, r);
    }

    return p;
}

static u_char *
ngx_rtmp_dash_write_segment_timeline(ngx_rtmp_session_t *s, ngx_rtmp_dash_ctx_t *ctx, u_char *p, u_char *last)
{

    ngx_uint_t              i, t, d, r;
    ngx_rtmp_dash_frag_t    *f;

    for (i = 0; i < ctx->nfrags; i++) {
        f = ngx_rtmp_dash_get_frag(s, i);

        if (i == 0) {
            t = f->timestamp;
            d = f->duration;
            r = 0;
        } else {
            if (f->duration == d) {
                r++;
            } else {
                p = ngx_rtmp_dash_write_segment(p, last, t, d, r);
                t = f->timestamp;
                d = f->duration;
                r = 0;
            }
        }

        if (i == ctx->nfrags - 1) {
            p = ngx_rtmp_dash_write_segment(p, last, t, d, r);
        }
    }

    return p;
}
ut0mt8 commented 6 years ago
if (ctx->has_video) {
        p = ngx_slprintf(buffer, last, NGX_RTMP_DASH_MANIFEST_VIDEO,
                         codec_ctx->width,
                         codec_ctx->height,
                         codec_ctx->frame_rate,
                         &ctx->name,
                         codec_ctx->avc_profile,
                         codec_ctx->avc_compat,
                         codec_ctx->avc_level,
                         codec_ctx->width,
                         codec_ctx->height,
                         codec_ctx->frame_rate,
                         (ngx_uint_t) (codec_ctx->video_data_rate * 1000),
                         name, sep,
                         name, sep);

        p = ngx_rtmp_dash_write_segment_timeline(s, ctx, p, last);
ut0mt8 commented 6 years ago
if (ctx->has_audio) {
        p = ngx_slprintf(buffer, last, NGX_RTMP_DASH_MANIFEST_AUDIO,
                         &ctx->name,
                         codec_ctx->audio_codec_id == NGX_RTMP_AUDIO_AAC ?
                         (codec_ctx->aac_sbr ? "40.5" : "40.2") : "6b",
                         codec_ctx->sample_rate,
                         (ngx_uint_t) (codec_ctx->audio_data_rate * 1000),
                         name, sep,
                         name, sep);

        p = ngx_rtmp_dash_write_segment_timeline(s, ctx, p, last);
ut0mt8 commented 6 years ago

first try done

ut0mt8 commented 6 years ago

Seems to works