Browse code

dvbsubdec: add version checking

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

JULIAN GARDNER authored on 2011/10/14 23:41:21
Showing 1 changed files
... ...
@@ -154,6 +154,7 @@ static void png_save2(const char *filename, uint32_t *bitmap, int w, int h)
154 154
 
155 155
 typedef struct DVBSubCLUT {
156 156
     int id;
157
+    int version;
157 158
 
158 159
     uint32_t clut4[4];
159 160
     uint32_t clut16[16];
... ...
@@ -180,6 +181,7 @@ typedef struct DVBSubObjectDisplay {
180 180
 
181 181
 typedef struct DVBSubObject {
182 182
     int id;
183
+    int version;
183 184
 
184 185
     int type;
185 186
 
... ...
@@ -199,6 +201,7 @@ typedef struct DVBSubRegionDisplay {
199 199
 
200 200
 typedef struct DVBSubRegion {
201 201
     int id;
202
+    int version;
202 203
 
203 204
     int width;
204 205
     int height;
... ...
@@ -229,6 +232,7 @@ typedef struct DVBSubContext {
229 229
     int composition_id;
230 230
     int ancillary_id;
231 231
 
232
+    int version;
232 233
     int time_out;
233 234
     DVBSubRegion *region_list;
234 235
     DVBSubCLUT   *clut_list;
... ...
@@ -375,6 +379,8 @@ static av_cold int dvbsub_init_decoder(AVCodecContext *avctx)
375 375
         ctx->ancillary_id   = AV_RB16(avctx->extradata + 2);
376 376
     }
377 377
 
378
+    ctx->version = -1;
379
+
378 380
     default_clut.id = -1;
379 381
     default_clut.next = NULL;
380 382
 
... ...
@@ -928,6 +934,7 @@ static void dvbsub_parse_clut_segment(AVCodecContext *avctx,
928 928
 
929 929
     const uint8_t *buf_end = buf + buf_size;
930 930
     int i, clut_id;
931
+    int version;
931 932
     DVBSubCLUT *clut;
932 933
     int entry_id, depth , full_range;
933 934
     int y, cr, cb, alpha;
... ...
@@ -945,6 +952,7 @@ static void dvbsub_parse_clut_segment(AVCodecContext *avctx,
945 945
         av_dlog(avctx, "\n");
946 946
 
947 947
     clut_id = *buf++;
948
+    version = ((*buf)>>4)&15;
948 949
     buf += 1;
949 950
 
950 951
     clut = get_clut(ctx, clut_id);
... ...
@@ -955,11 +963,16 @@ static void dvbsub_parse_clut_segment(AVCodecContext *avctx,
955 955
         memcpy(clut, &default_clut, sizeof(DVBSubCLUT));
956 956
 
957 957
         clut->id = clut_id;
958
+        clut->version = -1;
958 959
 
959 960
         clut->next = ctx->clut_list;
960 961
         ctx->clut_list = clut;
961 962
     }
962 963
 
964
+    if (clut->version != version) {
965
+
966
+    clut->version = version;
967
+
963 968
     while (buf + 4 < buf_end) {
964 969
         entry_id = *buf++;
965 970
 
... ...
@@ -1001,6 +1014,7 @@ static void dvbsub_parse_clut_segment(AVCodecContext *avctx,
1001 1001
         if (depth & 0x20)
1002 1002
             clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha);
1003 1003
     }
1004
+    }
1004 1005
 }
1005 1006
 
1006 1007
 
... ...
@@ -1011,6 +1025,7 @@ static void dvbsub_parse_region_segment(AVCodecContext *avctx,
1011 1011
 
1012 1012
     const uint8_t *buf_end = buf + buf_size;
1013 1013
     int region_id, object_id;
1014
+    int version;
1014 1015
     DVBSubRegion *region;
1015 1016
     DVBSubObject *object;
1016 1017
     DVBSubObjectDisplay *display;
... ...
@@ -1027,11 +1042,13 @@ static void dvbsub_parse_region_segment(AVCodecContext *avctx,
1027 1027
         region = av_mallocz(sizeof(DVBSubRegion));
1028 1028
 
1029 1029
         region->id = region_id;
1030
+        region->version = -1;
1030 1031
 
1031 1032
         region->next = ctx->region_list;
1032 1033
         ctx->region_list = region;
1033 1034
     }
1034 1035
 
1036
+    version = ((*buf)>>4) & 15;
1035 1037
     fill = ((*buf++) >> 3) & 1;
1036 1038
 
1037 1039
     region->width = AV_RB16(buf);
... ...
@@ -1127,13 +1144,21 @@ static void dvbsub_parse_page_segment(AVCodecContext *avctx,
1127 1127
     const uint8_t *buf_end = buf + buf_size;
1128 1128
     int region_id;
1129 1129
     int page_state;
1130
+    int timeout;
1131
+    int version;
1130 1132
 
1131 1133
     if (buf_size < 1)
1132 1134
         return;
1133 1135
 
1134
-    ctx->time_out = *buf++;
1136
+    timeout = *buf++;
1137
+    version = ((*buf)>>4) & 15;
1135 1138
     page_state = ((*buf++) >> 2) & 3;
1136 1139
 
1140
+    if (ctx->version != version) {
1141
+
1142
+    ctx->time_out = timeout;
1143
+    ctx->version = version;
1144
+
1137 1145
     av_dlog(avctx, "Page time out %ds, state %d\n", ctx->time_out, page_state);
1138 1146
 
1139 1147
     if (page_state == 1 || page_state == 2) {
... ...
@@ -1184,6 +1209,7 @@ static void dvbsub_parse_page_segment(AVCodecContext *avctx,
1184 1184
 
1185 1185
         av_free(display);
1186 1186
     }
1187
+    }
1187 1188
 
1188 1189
 }
1189 1190