~ubuntu-branches/debian/sid/ffmpeg/sid

« back to all changes in this revision

Viewing changes to libavcodec/dvbsubdec.c

  • Committer: Package Import Robot
  • Author(s): Andreas Cadhalpun, Fabian Greffrath, Andreas Cadhalpun
  • Date: 2015-09-22 15:15:20 UTC
  • mfrom: (0.1.29)
  • Revision ID: package-import@ubuntu.com-20150922151520-hhmd3in9ykigjvs9
Tags: 7:2.8-1
[ Fabian Greffrath ]
* Pass the --dbg-package=ffmpeg-dbg parameter only to dh_strip.
* Add alternative Depends: libavcodec-ffmpeg-extra56 to libavcodec-dev and
  ffmpeg-dbg to allow for building and debugging with this library installed.

[ Andreas Cadhalpun ]
* Import new major upstream release 2.8.
* Remove the transitional lib*-ffmpeg-dev packages.
* Drop old Breaks on kodi-bin.
* Drop workaround for sparc, which is no Debian architecture anymore.
* Re-enable x265 on alpha, as it's available again.
* Disable unavailable frei0r, opencv and x264 on mips64el.
* Disable libopenjpeg (#787275) and libschroedinger (#787957) decoders.
  (Closes: #786670)
* Disable libdc1394 on sparc64, because it links against the broken due to
  #790560 libudev1.
* Enable libsnappy support.
* Add new symbols.
* Update debian/copyright.
* Update debian/tests/encdec_list.txt.
* Add hls-only-seek-if-there-is-an-offset.patch. (Closes: #798189)
* Add 'Breaks: libavutil-ffmpeg54 (>= 8:0)' to the libraries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
237
237
    int time_out;
238
238
    int compute_edt; /**< if 1 end display time calculated using pts
239
239
                          if 0 (Default) calculated using time out */
 
240
    int compute_clut;
 
241
    int substream;
240
242
    int64_t prev_start;
241
243
    DVBSubRegion *region_list;
242
244
    DVBSubCLUT   *clut_list;
367
369
    int i, r, g, b, a = 0;
368
370
    DVBSubContext *ctx = avctx->priv_data;
369
371
 
370
 
    if (!avctx->extradata || (avctx->extradata_size < 4) || ((avctx->extradata_size % 5 != 0) && (avctx->extradata_size != 4))) {
 
372
    if (ctx->substream < 0) {
 
373
        ctx->composition_id = -1;
 
374
        ctx->ancillary_id   = -1;
 
375
    } else if (!avctx->extradata || (avctx->extradata_size < 4) || ((avctx->extradata_size % 5 != 0) && (avctx->extradata_size != 4))) {
371
376
        av_log(avctx, AV_LOG_WARNING, "Invalid DVB subtitles stream extradata!\n");
372
377
        ctx->composition_id = -1;
373
378
        ctx->ancillary_id   = -1;
374
379
    } else {
375
 
        if (avctx->extradata_size > 5) {
376
 
            av_log(avctx, AV_LOG_WARNING, "Decoding first DVB subtitles sub-stream\n");
 
380
        if (avctx->extradata_size > 5*ctx->substream + 2) {
 
381
            ctx->composition_id = AV_RB16(avctx->extradata + 5*ctx->substream);
 
382
            ctx->ancillary_id   = AV_RB16(avctx->extradata + 5*ctx->substream + 2);
 
383
        } else {
 
384
            av_log(avctx, AV_LOG_WARNING, "Selected DVB subtitles sub-stream %d is not available\n", ctx->substream);
 
385
            ctx->composition_id = AV_RB16(avctx->extradata);
 
386
            ctx->ancillary_id   = AV_RB16(avctx->extradata + 2);
377
387
        }
378
 
 
379
 
        ctx->composition_id = AV_RB16(avctx->extradata);
380
 
        ctx->ancillary_id   = AV_RB16(avctx->extradata + 2);
381
388
    }
382
389
 
383
390
    ctx->version = -1;
754
761
    return pixels_read;
755
762
}
756
763
 
 
764
static void compute_default_clut(AVPicture *frame, int w, int h)
 
765
{
 
766
    uint8_t list[256] = {0};
 
767
    uint8_t list_inv[256];
 
768
    int counttab[256] = {0};
 
769
    int count, i, x, y;
 
770
 
 
771
#define V(x,y) frame->data[0][(x) + (y)*frame->linesize[0]]
 
772
    for (y = 0; y<h; y++) {
 
773
        for (x = 0; x<w; x++) {
 
774
            int v = V(x,y) + 1;
 
775
            int vl = x     ? V(x-1,y) + 1 : 0;
 
776
            int vr = x+1<w ? V(x+1,y) + 1 : 0;
 
777
            int vt = y     ? V(x,y-1) + 1 : 0;
 
778
            int vb = y+1<h ? V(x,y+1) + 1 : 0;
 
779
            counttab[v-1] += !!((v!=vl) + (v!=vr) + (v!=vt) + (v!=vb));
 
780
        }
 
781
    }
 
782
#define L(x,y) list[ frame->data[0][(x) + (y)*frame->linesize[0]] ]
 
783
 
 
784
    for (i = 0; i<256; i++) {
 
785
        int scoretab[256] = {0};
 
786
        int bestscore = 0;
 
787
        int bestv = 0;
 
788
        for (y = 0; y<h; y++) {
 
789
            for (x = 0; x<w; x++) {
 
790
                int v = frame->data[0][x + y*frame->linesize[0]];
 
791
                int l_m = list[v];
 
792
                int l_l = x     ? L(x-1, y) : 1;
 
793
                int l_r = x+1<w ? L(x+1, y) : 1;
 
794
                int l_t = y     ? L(x, y-1) : 1;
 
795
                int l_b = y+1<h ? L(x, y+1) : 1;
 
796
                int score;
 
797
                if (l_m)
 
798
                    continue;
 
799
                scoretab[v] += l_l + l_r + l_t + l_b;
 
800
                score = 1024LL*scoretab[v] / counttab[v];
 
801
                if (score > bestscore) {
 
802
                    bestscore = score;
 
803
                    bestv = v;
 
804
                }
 
805
            }
 
806
        }
 
807
        if (!bestscore)
 
808
            break;
 
809
        list    [ bestv ] = 1;
 
810
        list_inv[     i ] = bestv;
 
811
    }
 
812
 
 
813
    count = i - 1;
 
814
    for (i--; i>=0; i--) {
 
815
        int v = i*255/count;
 
816
        AV_WN32(frame->data[1] + 4*list_inv[i], RGBA(v/2,v,v/2,v));
 
817
    }
 
818
}
 
819
 
 
820
 
757
821
static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_output)
758
822
{
759
823
    DVBSubContext *ctx = avctx->priv_data;
775
839
 
776
840
    /* Not touching AVSubtitles again*/
777
841
    if(sub->num_rects) {
778
 
        avpriv_request_sample(ctx, "Different Version of Segment asked Twice\n");
 
842
        avpriv_request_sample(ctx, "Different Version of Segment asked Twice");
779
843
        return AVERROR_PATCHWELCOME;
780
844
    }
781
845
    for (display = ctx->display_list; display; display = display->next) {
855
919
 
856
920
            memcpy(rect->pict.data[0], region->pbuf, region->buf_size);
857
921
 
 
922
            if ((clut == &default_clut && ctx->compute_clut == -1) || ctx->compute_clut == 1)
 
923
                compute_default_clut(&rect->pict, rect->w, rect->h);
 
924
 
858
925
            i++;
859
926
        }
860
927
    }
1023
1090
        buf += 2;
1024
1091
 
1025
1092
        if (buf + top_field_len + bottom_field_len > buf_end) {
1026
 
            av_log(avctx, AV_LOG_ERROR, "Field data size too large\n");
 
1093
            av_log(avctx, AV_LOG_ERROR, "Field data size %d+%d too large\n", top_field_len, bottom_field_len);
1027
1094
            return AVERROR_INVALIDDATA;
1028
1095
        }
1029
1096
 
1107
1174
 
1108
1175
        if (depth == 0) {
1109
1176
            av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\n", *buf);
1110
 
            return AVERROR_INVALIDDATA;
1111
1177
        }
1112
1178
 
1113
1179
        full_range = (*buf++) & 1;
1545
1611
    int i;
1546
1612
    int ret = 0;
1547
1613
    int got_segment = 0;
 
1614
    int got_dds = 0;
1548
1615
 
1549
1616
    ff_dlog(avctx, "DVB sub packet:\n");
1550
1617
 
1607
1674
            case DVBSUB_DISPLAYDEFINITION_SEGMENT:
1608
1675
                ret = dvbsub_parse_display_definition_segment(avctx, p,
1609
1676
                                                              segment_length);
 
1677
                got_dds = 1;
1610
1678
                break;
1611
1679
            case DVBSUB_DISPLAY_SEGMENT:
1612
1680
                ret = dvbsub_display_end_segment(avctx, p, segment_length, sub, data_size);
 
1681
                if (got_segment == 15 && !got_dds && !avctx->width && !avctx->height) {
 
1682
                    // Default from ETSI EN 300 743 V1.3.1 (7.2.1)
 
1683
                    avctx->width  = 720;
 
1684
                    avctx->height = 576;
 
1685
                }
1613
1686
                got_segment |= 16;
1614
1687
                break;
1615
1688
            default:
1645
1718
 
1646
1719
#define DS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_SUBTITLE_PARAM
1647
1720
static const AVOption options[] = {
1648
 
    {"compute_edt", "compute end of time using pts or timeout", offsetof(DVBSubContext, compute_edt), FF_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DS},
 
1721
    {"compute_edt", "compute end of time using pts or timeout", offsetof(DVBSubContext, compute_edt), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DS},
 
1722
    {"compute_clut", "compute clut when not available(-1) or always(1) or never(0)", offsetof(DVBSubContext, compute_clut), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, DS},
 
1723
    {"dvb_substream", "", offsetof(DVBSubContext, substream), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, DS},
1649
1724
    {NULL}
1650
1725
};
1651
1726
static const AVClass dvbsubdec_class = {