Changeset 6ba2378ea683a7cbab6739cb18b64324ba56a377
- Timestamp:
- 13/05/08 08:10:36
(7 months ago)
- Author:
- Jean-Baptiste Kempf <jb@videolan.org>
- git-committer:
- Jean-Baptiste Kempf <jb@videolan.org> 1210659036 -0700
- git-parent:
[2828d7d1b3f14983d09f5cfb12b4ce13c8b827ed]
- git-author:
- Jean-Baptiste Kempf <jb@videolan.org> 1210659021 -0700
- Message:
Cosmetic, malloc checks and options completion.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r6f9ce7c |
r6ba2378 |
|
| 7 | 7 | * Authors: Laurent Aimar <fenrir@via.ecp.fr> |
|---|
| 8 | 8 | * Derk-Jan Hartman <hartman at videolan dot org> |
|---|
| | 9 | * Jean-Baptiste Kempf <jb@videolan.org> |
|---|
| 9 | 10 | * |
|---|
| 10 | 11 | * This program is free software; you can redistribute it and/or modify |
|---|
| … | … | |
| 58 | 59 | N_("Force the subtiles format. Valid values are : \"microdvd\", " \ |
|---|
| 59 | 60 | "\"subrip\", \"ssa1\", \"ssa2-4\", \"ass\", \"vplayer\" " \ |
|---|
| 60 | | "\"sami\", \"dvdsubtitle\", \"mpl2\", \"aqt\", \"pjs\" and \"auto\" (meaning autodetection, this " \ |
|---|
| | 61 | "\"sami\", \"dvdsubtitle\", \"mpl2\", \"aqt\", \"pjs\" "\ |
|---|
| | 62 | "\"mpsub\" \"jacosub\" and \"auto\" (meaning autodetection, this " \ |
|---|
| 61 | 63 | "should always work).") |
|---|
| 62 | 64 | static const char *ppsz_sub_type[] = |
|---|
| … | … | |
| 64 | 66 | "auto", "microdvd", "subrip", "subviewer", "ssa1", |
|---|
| 65 | 67 | "ssa2-4", "ass", "vplayer", "sami", "dvdsubtitle", "mpl2", |
|---|
| 66 | | "aqt", "pjs" |
|---|
| | 68 | "aqt", "pjs", "mpsub", "jacosub" |
|---|
| 67 | 69 | }; |
|---|
| 68 | 70 | |
|---|
| … | … | |
| 218 | 220 | p_demux->pf_control = Control; |
|---|
| 219 | 221 | p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); |
|---|
| | 222 | if( p_sys == NULL ) |
|---|
| | 223 | return VLC_ENOMEM; |
|---|
| | 224 | |
|---|
| 220 | 225 | p_sys->psz_header = NULL; |
|---|
| 221 | 226 | p_sys->i_subtitle = 0; |
|---|
| … | … | |
| 741 | 746 | int i_idx ) |
|---|
| 742 | 747 | { |
|---|
| | 748 | VLC_UNUSED( i_idx ); |
|---|
| 743 | 749 | demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 744 | 750 | text_t *txt = &p_sys->txt; |
|---|
| … | … | |
| 887 | 893 | int i_idx ) |
|---|
| 888 | 894 | { |
|---|
| | 895 | VLC_UNUSED( i_idx ); |
|---|
| 889 | 896 | return ParseSubRipSubViewer( p_demux, p_subtitle, |
|---|
| 890 | 897 | "%d:%d:%d,%d --> %d:%d:%d,%d", |
|---|
| … | … | |
| 896 | 903 | int i_idx ) |
|---|
| 897 | 904 | { |
|---|
| | 905 | VLC_UNUSED( i_idx ); |
|---|
| | 906 | |
|---|
| 898 | 907 | return ParseSubRipSubViewer( p_demux, p_subtitle, |
|---|
| 899 | 908 | "%d:%d:%d.%d,%d:%d:%d.%d", |
|---|
| … | … | |
| 997 | 1006 | int i_idx ) |
|---|
| 998 | 1007 | { |
|---|
| | 1008 | VLC_UNUSED( i_idx ); |
|---|
| | 1009 | |
|---|
| 999 | 1010 | demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 1000 | 1011 | text_t *txt = &p_sys->txt; |
|---|
| … | … | |
| 1062 | 1073 | static int ParseSami( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) |
|---|
| 1063 | 1074 | { |
|---|
| | 1075 | VLC_UNUSED( i_idx ); |
|---|
| 1064 | 1076 | demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 1065 | 1077 | text_t *txt = &p_sys->txt; |
|---|
| … | … | |
| 1160 | 1172 | int i_idx ) |
|---|
| 1161 | 1173 | { |
|---|
| | 1174 | VLC_UNUSED( i_idx ); |
|---|
| | 1175 | |
|---|
| 1162 | 1176 | demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 1163 | 1177 | text_t *txt = &p_sys->txt; |
|---|
| … | … | |
| 1224 | 1238 | static int ParseMPL2( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) |
|---|
| 1225 | 1239 | { |
|---|
| | 1240 | VLC_UNUSED( i_idx ); |
|---|
| | 1241 | |
|---|
| 1226 | 1242 | demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 1227 | 1243 | text_t *txt = &p_sys->txt; |
|---|
| … | … | |
| 1272 | 1288 | static int ParseAQT( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) |
|---|
| 1273 | 1289 | { |
|---|
| | 1290 | VLC_UNUSED( i_idx ); |
|---|
| | 1291 | |
|---|
| 1274 | 1292 | demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 1275 | 1293 | text_t *txt = &p_sys->txt; |
|---|
| … | … | |
| 1324 | 1342 | static int ParsePJS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) |
|---|
| 1325 | 1343 | { |
|---|
| | 1344 | VLC_UNUSED( i_idx ); |
|---|
| | 1345 | |
|---|
| 1326 | 1346 | demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 1327 | 1347 | text_t *txt = &p_sys->txt; |
|---|
| … | … | |
| 1337 | 1357 | |
|---|
| 1338 | 1358 | psz_text = malloc( strlen(s) + 1 ); |
|---|
| | 1359 | if( !psz_text ) |
|---|
| | 1360 | return VLC_ENOMEM; |
|---|
| 1339 | 1361 | |
|---|
| 1340 | 1362 | /* Data Lines */ |
|---|
| … | … | |
| 1361 | 1383 | static int ParseMPSub( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) |
|---|
| 1362 | 1384 | { |
|---|
| | 1385 | VLC_UNUSED( i_idx ); |
|---|
| | 1386 | |
|---|
| 1363 | 1387 | demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 1364 | 1388 | text_t *txt = &p_sys->txt; |
|---|
| … | … | |
| 1367 | 1391 | for( ;; ) |
|---|
| 1368 | 1392 | { |
|---|
| 1369 | | const char *s = TextGetLine( txt ); |
|---|
| 1370 | 1393 | float f1, f2; |
|---|
| 1371 | 1394 | char p_dummy; |
|---|
| 1372 | 1395 | char *psz_temp; |
|---|
| 1373 | 1396 | |
|---|
| | 1397 | const char *s = TextGetLine( txt ); |
|---|
| 1374 | 1398 | if( !s ) |
|---|
| 1375 | 1399 | return VLC_EGENERIC; |
|---|
| | 1400 | |
|---|
| 1376 | 1401 | if( strstr( s, "FORMAT" ) ) |
|---|
| 1377 | 1402 | { |
|---|
| … | … | |
| 1383 | 1408 | |
|---|
| 1384 | 1409 | psz_temp = malloc( strlen(s) ); |
|---|
| | 1410 | if( !psz_temp ) |
|---|
| | 1411 | return VLC_ENOMEM; |
|---|
| | 1412 | |
|---|
| 1385 | 1413 | if( sscanf( s, "FORMAT=%[^\r\n]", psz_temp ) ) |
|---|
| 1386 | 1414 | { |
|---|
| … | … | |
| 1434 | 1462 | static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx ) |
|---|
| 1435 | 1463 | { |
|---|
| | 1464 | VLC_UNUSED( i_idx ); |
|---|
| | 1465 | |
|---|
| 1436 | 1466 | demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 1437 | 1467 | text_t *txt = &p_sys->txt; |
|---|
| … | … | |
| 1452 | 1482 | |
|---|
| 1453 | 1483 | psz_text = malloc( strlen( s ) + 1 ); |
|---|
| | 1484 | if( !psz_text ) |
|---|
| | 1485 | return VLC_ENOMEM; |
|---|
| 1454 | 1486 | psz_orig = psz_text; |
|---|
| 1455 | 1487 | |
|---|
| | 1488 | /* Complete time lines */ |
|---|
| 1456 | 1489 | if( sscanf( s, "%d:%d:%d.%d %d:%d:%d.%d %[^\n\r]", |
|---|
| 1457 | 1490 | &h1, &m1, &s1, &f1, &h2, &m2, &s2, &f2, psz_text ) == 9 ) |
|---|
| … | … | |
| 1464 | 1497 | * 1000000; |
|---|
| 1465 | 1498 | } |
|---|
| | 1499 | /* Short time lines */ |
|---|
| 1466 | 1500 | else if( sscanf( s, "@%d @%d %[^\n\r]", &f1, &f2, psz_text ) == 3 ) |
|---|
| 1467 | 1501 | { |
|---|
| … | … | |
| 1471 | 1505 | ( f2 + jss_time_shift ) / jss_time_resolution * 1000000.0 ); |
|---|
| 1472 | 1506 | } |
|---|
| | 1507 | /* General Directive lines */ |
|---|
| | 1508 | /* Only TIME and SHIFT are supported so far */ |
|---|
| 1473 | 1509 | else if( s[0] == '#' ) |
|---|
| 1474 | 1510 | { |
|---|
| … | … | |
| 1481 | 1517 | switch( toupper( psz_text[1] ) ) |
|---|
| 1482 | 1518 | { |
|---|
| 1483 | | case 'S': |
|---|
| 1484 | | shift = isalpha( psz_text[2] ) ? 6 : 2 ; |
|---|
| 1485 | | |
|---|
| 1486 | | if( sscanf( &psz_text[shift], "%d", &h ) ) |
|---|
| | 1519 | case 'S': |
|---|
| | 1520 | shift = isalpha( psz_text[2] ) ? 6 : 2 ; |
|---|
| | 1521 | |
|---|
| | 1522 | if( sscanf( &psz_text[shift], "%d", &h ) ) |
|---|
| | 1523 | { |
|---|
| | 1524 | /* Negative shifting */ |
|---|
| | 1525 | if( h < 0 ) |
|---|
| 1487 | 1526 | { |
|---|
| 1488 | | /* Negative shifting */ |
|---|
| 1489 | | if( h < 0 ) |
|---|
| | 1527 | h *= -1; |
|---|
| | 1528 | inv = -1; |
|---|
| | 1529 | } |
|---|
| | 1530 | |
|---|
| | 1531 | if( sscanf( &psz_text[shift], "%*d:%d", &m ) ) |
|---|
| | 1532 | { |
|---|
| | 1533 | if( sscanf( &psz_text[shift], "%*d:%*d:%d", &sec ) ) |
|---|
| 1490 | 1534 | { |
|---|
| 1491 | | h *= -1; |
|---|
| 1492 | | inv = -1; |
|---|
| 1493 | | } |
|---|
| 1494 | | |
|---|
| 1495 | | if( sscanf( &psz_text[shift], "%*d:%d", &m ) ) |
|---|
| 1496 | | { |
|---|
| 1497 | | if( sscanf( &psz_text[shift], "%*d:%*d:%d", &sec ) ) |
|---|
| 1498 | | { |
|---|
| 1499 | | sscanf( &psz_text[shift], "%*d:%*d:%*d.%d", &f ); |
|---|
| 1500 | | } |
|---|
| 1501 | | else |
|---|
| 1502 | | { |
|---|
| 1503 | | h = 0; |
|---|
| 1504 | | sscanf( &psz_text[shift], "%d:%d.%d", &m, &sec, &f ); |
|---|
| 1505 | | m *= inv; |
|---|
| 1506 | | } |
|---|
| | 1535 | sscanf( &psz_text[shift], "%*d:%*d:%*d.%d", &f ); |
|---|
| 1507 | 1536 | } |
|---|
| 1508 | 1537 | else |
|---|
| 1509 | 1538 | { |
|---|
| 1510 | | h = m = 0; |
|---|
| 1511 | | sscanf( &psz_text[shift], "%d.%d", &sec, &f); |
|---|
| 1512 | | sec *= inv; |
|---|
| | 1539 | h = 0; |
|---|
| | 1540 | sscanf( &psz_text[shift], "%d:%d.%d", |
|---|
| | 1541 | &m, &sec, &f ); |
|---|
| | 1542 | m *= inv; |
|---|
| 1513 | 1543 | } |
|---|
| 1514 | | jss_time_shift = ( ( h * 3600 + m * 60 + sec ) |
|---|
| 1515 | | * jss_time_resolution + f ) * inv; |
|---|
| 1516 | 1544 | } |
|---|
| 1517 | | break; |
|---|
| 1518 | | |
|---|
| 1519 | | case 'T': |
|---|
| 1520 | | shift = isalpha( psz_text[2] ) ? 8 : 2 ; |
|---|
| 1521 | | |
|---|
| 1522 | | sscanf( &psz_text[shift], "%d", &jss_time_resolution ); |
|---|
| 1523 | | break; |
|---|
| | 1545 | else |
|---|
| | 1546 | { |
|---|
| | 1547 | h = m = 0; |
|---|
| | 1548 | sscanf( &psz_text[shift], "%d.%d", &sec, &f); |
|---|
| | 1549 | sec *= inv; |
|---|
| | 1550 | } |
|---|
| | 1551 | jss_time_shift = ( ( h * 3600 + m * 60 + sec ) |
|---|
| | 1552 | * jss_time_resolution + f ) * inv; |
|---|
| | 1553 | } |
|---|
| | 1554 | break; |
|---|
| | 1555 | |
|---|
| | 1556 | case 'T': |
|---|
| | 1557 | shift = isalpha( psz_text[2] ) ? 8 : 2 ; |
|---|
| | 1558 | |
|---|
| | 1559 | sscanf( &psz_text[shift], "%d", &jss_time_resolution ); |
|---|
| | 1560 | break; |
|---|
| 1524 | 1561 | } |
|---|
| 1525 | 1562 | free( psz_text ); |
|---|
| … | … | |
| 1527 | 1564 | } |
|---|
| 1528 | 1565 | else |
|---|
| 1529 | | /* Unkown line */ |
|---|
| | 1566 | /* Unkown type line, probably a comment */ |
|---|
| 1530 | 1567 | { |
|---|
| 1531 | 1568 | free( psz_text ); |
|---|
| … | … | |
| 1543 | 1580 | |
|---|
| 1544 | 1581 | /* Directives are NOT parsed yet */ |
|---|
| | 1582 | /* This has probably a better place in a decoder ? */ |
|---|
| 1545 | 1583 | /* directive = malloc( strlen( psz_text ) + 1 ); |
|---|
| 1546 | 1584 | if( sscanf( psz_text, "%s %[^\n\r]", directive, psz_text2 ) == 2 )*/ |
|---|
| … | … | |
| 1550 | 1588 | while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++; |
|---|
| 1551 | 1589 | |
|---|
| | 1590 | |
|---|
| | 1591 | /* Clean all the lines from inline comments and other stuffs */ |
|---|
| 1552 | 1592 | psz_text2 = calloc( strlen( psz_text) + 1, 1 ); |
|---|
| 1553 | 1593 | psz_orig2 = psz_text2; |
|---|
| … | … | |
| 1638 | 1678 | } |
|---|
| 1639 | 1679 | } |
|---|
| | 1680 | |
|---|