Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
20275a0b
Commit
20275a0b
authored
Jan 05, 2004
by
Laurent Aimar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* nsv: clean up, added seek support.
parent
bcf186fd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
223 additions
and
121 deletions
+223
-121
modules/demux/nsv.c
modules/demux/nsv.c
+223
-121
No files found.
modules/demux/nsv.c
View file @
20275a0b
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* nsv.c: NullSoft Video demuxer.
* nsv.c: NullSoft Video demuxer.
*****************************************************************************
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* Copyright (C) 2004 VideoLAN
* $Id: nsv.c,v 1.
1 2004/01/04 14:28:11
fenrir Exp $
* $Id: nsv.c,v 1.
2 2004/01/05 03:19:00
fenrir Exp $
*
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
*
...
@@ -29,6 +29,12 @@
...
@@ -29,6 +29,12 @@
#include <vlc/vlc.h>
#include <vlc/vlc.h>
#include <vlc/input.h>
#include <vlc/input.h>
/* TODO:
* - implement NSVf parsing (to get meta data)
* - implement missing Control (and in the right way)
* - ...
*/
/*****************************************************************************
/*****************************************************************************
* Module descriptor
* Module descriptor
*****************************************************************************/
*****************************************************************************/
...
@@ -37,7 +43,7 @@ static void Close ( vlc_object_t * );
...
@@ -37,7 +43,7 @@ static void Close ( vlc_object_t * );
vlc_module_begin
();
vlc_module_begin
();
set_description
(
_
(
"NullSoft demuxer"
)
);
set_description
(
_
(
"NullSoft demuxer"
)
);
set_capability
(
"demux2"
,
1
);
set_capability
(
"demux2"
,
1
0
);
set_callbacks
(
Open
,
Close
);
set_callbacks
(
Open
,
Close
);
add_shortcut
(
"nsv"
);
add_shortcut
(
"nsv"
);
vlc_module_end
();
vlc_module_end
();
...
@@ -55,12 +61,18 @@ struct demux_sys_t
...
@@ -55,12 +61,18 @@ struct demux_sys_t
es_out_id_t
*
p_video
;
es_out_id_t
*
p_video
;
int64_t
i_pcr
;
int64_t
i_pcr
;
int64_t
i_time
;
int64_t
i_pcr_inc
;
int64_t
i_pcr_inc
;
};
};
static
int
Demux
(
demux_t
*
p_demux
);
static
int
Demux
(
demux_t
*
p_demux
);
static
int
Control
(
demux_t
*
p_demux
,
int
i_query
,
va_list
args
);
static
int
Control
(
demux_t
*
p_demux
,
int
i_query
,
va_list
args
);
static
int
ReSynch
(
demux_t
*
p_demux
);
static
int
ReadNSVf
(
demux_t
*
p_demux
);
static
int
ReadNSVs
(
demux_t
*
p_demux
);
/*****************************************************************************
/*****************************************************************************
* Open
* Open
*****************************************************************************/
*****************************************************************************/
...
@@ -78,15 +90,20 @@ static int Open( vlc_object_t *p_this )
...
@@ -78,15 +90,20 @@ static int Open( vlc_object_t *p_this )
return
VLC_EGENERIC
;
return
VLC_EGENERIC
;
}
}
if
(
strncmp
(
p_peek
,
"NSVf"
,
4
)
&&
strncmp
(
p_peek
,
"NSVs"
,
4
))
if
(
strncmp
(
p_peek
,
"NSVf"
,
4
)
&&
strncmp
(
p_peek
,
"NSVs"
,
4
))
{
/* In case we had force this demuxer we try to resynch */
if
(
strcmp
(
p_demux
->
psz_demux
,
"nsv"
)
||
ReSynch
(
p_demux
)
)
{
{
msg_Warn
(
p_demux
,
"NSV module discarded"
);
msg_Warn
(
p_demux
,
"NSV module discarded"
);
return
VLC_EGENERIC
;
return
VLC_EGENERIC
;
}
}
}
/* Fill p_demux field */
/* Fill p_demux field */
p_demux
->
pf_demux
=
Demux
;
p_demux
->
pf_demux
=
Demux
;
p_demux
->
pf_control
=
Control
;
p_demux
->
pf_control
=
Control
;
p_demux
->
p_sys
=
p_sys
=
malloc
(
sizeof
(
demux_sys_t
)
);
p_demux
->
p_sys
=
p_sys
=
malloc
(
sizeof
(
demux_sys_t
)
);
es_format_Init
(
&
p_sys
->
fmt_audio
,
AUDIO_ES
,
0
);
es_format_Init
(
&
p_sys
->
fmt_audio
,
AUDIO_ES
,
0
);
p_sys
->
p_audio
=
NULL
;
p_sys
->
p_audio
=
NULL
;
...
@@ -94,18 +111,9 @@ static int Open( vlc_object_t *p_this )
...
@@ -94,18 +111,9 @@ static int Open( vlc_object_t *p_this )
p_sys
->
p_video
=
NULL
;
p_sys
->
p_video
=
NULL
;
p_sys
->
i_pcr
=
1
;
p_sys
->
i_pcr
=
1
;
p_sys
->
i_time
=
0
;
p_sys
->
i_pcr_inc
=
0
;
p_sys
->
i_pcr_inc
=
0
;
/* Parse the headers */
if
(
!
strncmp
(
p_peek
,
"NSVf"
,
4
)
)
{
int
i_size
=
GetDWLE
(
&
p_peek
[
4
]
);
/* For now skip it */
stream_Read
(
p_demux
->
s
,
NULL
,
i_size
);
}
return
VLC_SUCCESS
;
return
VLC_SUCCESS
;
}
}
...
@@ -128,130 +136,54 @@ static int Demux( demux_t *p_demux )
...
@@ -128,130 +136,54 @@ static int Demux( demux_t *p_demux )
{
{
demux_sys_t
*
p_sys
=
p_demux
->
p_sys
;
demux_sys_t
*
p_sys
=
p_demux
->
p_sys
;
uint8_t
header
[
19
];
uint8_t
header
[
5
];
uint8_t
*
p_peek
;
uint8_t
*
p_peek
;
int
i_size
;
int
i_size
;
block_t
*
p_frame
;
block_t
*
p_frame
;
if
(
stream_Peek
(
p_demux
->
s
,
&
p_peek
,
4
)
<
4
)
for
(
;;
)
{
if
(
stream_Peek
(
p_demux
->
s
,
&
p_peek
,
8
)
<
8
)
{
{
msg_Warn
(
p_demux
,
"cannot peek"
);
msg_Warn
(
p_demux
,
"cannot peek"
);
return
0
;
return
0
;
}
}
if
(
GetWLE
(
p_peek
)
==
0xbeef
)
if
(
!
strncmp
(
p_peek
,
"NSVf"
,
4
)
)
{
{
if
(
stream_Read
(
p_demux
->
s
,
NULL
,
2
)
<
2
)
if
(
ReadNSVf
(
p_demux
)
)
{
{
msg_Warn
(
p_demux
,
"cannot read"
);
return
-
1
;
return
0
;
}
}
}
}
else
if
(
!
strncmp
(
p_peek
,
"NSVs"
,
4
)
)
else
if
(
!
strncmp
(
p_peek
,
"NSVs"
,
4
)
)
{
{
vlc_fourcc_t
fcc
;
if
(
ReadNSVs
(
p_demux
)
)
if
(
stream_Read
(
p_demux
->
s
,
header
,
19
)
<
19
)
{
{
msg_Warn
(
p_demux
,
"cannot read"
);
return
-
1
;
return
0
;
}
}
msg_Dbg
(
p_demux
,
"New NSVs chunk"
);
/* Video */
switch
(
(
fcc
=
VLC_FOURCC
(
header
[
4
],
header
[
5
],
header
[
6
],
header
[
7
]
)
)
)
{
case
VLC_FOURCC
(
'V'
,
'P'
,
'3'
,
' '
):
case
VLC_FOURCC
(
'V'
,
'P'
,
'3'
,
'1'
):
fcc
=
VLC_FOURCC
(
'V'
,
'P'
,
'3'
,
'1'
);
break
;
break
;
case
VLC_FOURCC
(
'N'
,
'O'
,
'N'
,
'E'
):
break
;
default:
msg_Warn
(
p_demux
,
"unknow codec"
);
break
;
}
if
(
fcc
!=
VLC_FOURCC
(
'N'
,
'O'
,
'N'
,
'E'
)
&&
fcc
!=
p_sys
->
fmt_video
.
i_codec
)
{
es_format_Init
(
&
p_sys
->
fmt_video
,
VIDEO_ES
,
fcc
);
p_sys
->
fmt_video
.
video
.
i_width
=
GetWLE
(
&
header
[
12
]
);
p_sys
->
fmt_video
.
video
.
i_height
=
GetWLE
(
&
header
[
14
]
);
if
(
p_sys
->
p_video
)
{
es_out_Del
(
p_demux
->
out
,
p_sys
->
p_video
);
}
p_sys
->
p_video
=
es_out_Add
(
p_demux
->
out
,
&
p_sys
->
fmt_video
);
msg_Dbg
(
p_demux
,
" - video `%4.4s' %dx%d"
,
(
char
*
)
&
fcc
,
p_sys
->
fmt_video
.
video
.
i_width
,
p_sys
->
fmt_video
.
video
.
i_height
);
}
}
else
if
(
GetWLE
(
p_peek
)
==
0xbeef
)
/* Audio */
switch
(
(
fcc
=
VLC_FOURCC
(
header
[
8
],
header
[
9
],
header
[
10
],
header
[
11
]
)
)
)
{
{
case
VLC_FOURCC
(
'M'
,
'P'
,
'3'
,
' '
):
/* Next frame of the current NSVs chunk */
fcc
=
VLC_FOURCC
(
'm'
,
'p'
,
'g'
,
'a'
);
if
(
stream_Read
(
p_demux
->
s
,
NULL
,
2
)
<
2
)
break
;
case
VLC_FOURCC
(
'P'
,
'C'
,
'M'
,
' '
):
fcc
=
VLC_FOURCC
(
'a'
,
'r'
,
'a'
,
'w'
);
break
;
case
VLC_FOURCC
(
'N'
,
'O'
,
'N'
,
'E'
):
break
;
default:
msg_Warn
(
p_demux
,
"unknow codec"
);
break
;
}
if
(
fcc
!=
VLC_FOURCC
(
'N'
,
'O'
,
'N'
,
'E'
)
&&
fcc
!=
p_sys
->
fmt_audio
.
i_codec
)
{
msg_Dbg
(
p_demux
,
" - audio `%4.4s'"
,
(
char
*
)
&
fcc
);
if
(
p_sys
->
p_audio
)
{
{
es_out_Del
(
p_demux
->
out
,
p_sys
->
p_audio
);
msg_Warn
(
p_demux
,
"cannot read"
);
p_sys
->
p_audio
=
NULL
;
return
0
;
}
es_format_Init
(
&
p_sys
->
fmt_audio
,
AUDIO_ES
,
fcc
);
}
}
if
(
header
[
16
]
&
0x80
)
{
switch
(
header
[
16
]
&
0x7f
)
{
case
1
:
/* 29.97 fps */
p_sys
->
i_pcr_inc
=
33367
;
break
;
case
3
:
/* 23.976 fps */
p_sys
->
i_pcr_inc
=
41708
;
break
;
case
5
:
/* 14.98 fps */
p_sys
->
i_pcr_inc
=
66755
;
break
;
default:
msg_Dbg
(
p_demux
,
"unknow fps (0x%x)"
,
header
[
16
]
);
p_sys
->
i_pcr_inc
=
40000
;
break
;
break
;
}
}
}
else
if
(
header
[
16
]
!=
0
)
{
p_sys
->
i_pcr_inc
=
1000000
/
header
[
16
];
}
else
{
msg_Dbg
(
p_demux
,
"invalid fps (0x00)"
);
p_sys
->
i_pcr_inc
=
40000
;
}
msg_Dbg
(
p_demux
,
" - fps=%.3f"
,
1000000
.
0
/
(
double
)
p_sys
->
i_pcr_inc
);
}
else
else
{
{
msg_Err
(
p_demux
,
"invalid signature 0x%x (%4.4s)"
,
*
(
uint32_t
*
)
p_peek
,
(
char
*
)
p_peek
);
msg_Err
(
p_demux
,
"invalid signature 0x%x (%4.4s)"
,
*
(
uint32_t
*
)
p_peek
,
(
char
*
)
p_peek
);
if
(
ReSynch
(
p_demux
)
)
{
return
-
1
;
return
-
1
;
}
}
}
}
if
(
stream_Read
(
p_demux
->
s
,
header
,
5
)
<
5
)
if
(
stream_Read
(
p_demux
->
s
,
header
,
5
)
<
5
)
{
{
...
@@ -279,7 +211,6 @@ static int Demux( demux_t *p_demux )
...
@@ -279,7 +211,6 @@ static int Demux( demux_t *p_demux )
if
(
i_size
>
0
)
if
(
i_size
>
0
)
{
{
/* msg_Dbg( p_demux, "frame audio size=%d", i_size ); */
/* msg_Dbg( p_demux, "frame audio size=%d", i_size ); */
if
(
p_sys
->
fmt_audio
.
i_codec
==
VLC_FOURCC
(
'a'
,
'r'
,
'a'
,
'w'
)
)
if
(
p_sys
->
fmt_audio
.
i_codec
==
VLC_FOURCC
(
'a'
,
'r'
,
'a'
,
'w'
)
)
{
{
uint8_t
h
[
4
];
uint8_t
h
[
4
];
...
@@ -304,6 +235,10 @@ static int Demux( demux_t *p_demux )
...
@@ -304,6 +235,10 @@ static int Demux( demux_t *p_demux )
}
}
p_sys
->
i_pcr
+=
p_sys
->
i_pcr_inc
;
p_sys
->
i_pcr
+=
p_sys
->
i_pcr_inc
;
if
(
p_sys
->
i_time
>=
0
)
{
p_sys
->
i_time
+=
p_sys
->
i_pcr_inc
;
}
return
1
;
return
1
;
}
}
...
@@ -331,25 +266,30 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
...
@@ -331,25 +266,30 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
*
pf
=
0
.
0
;
*
pf
=
0
.
0
;
}
}
return
VLC_SUCCESS
;
return
VLC_SUCCESS
;
#if 0
case
DEMUX_SET_POSITION
:
case
DEMUX_SET_POSITION
:
f
=
(
double
)
va_arg
(
args
,
double
);
f
=
(
double
)
va_arg
(
args
,
double
);
i64
=
stream_Size
(
p_demux
->
s
);
i64
=
stream_Size
(
p_demux
->
s
);
es_out_Control
(
p_demux
->
out
,
ES_OUT_RESET_PCR
);
es_out_Control
(
p_demux
->
out
,
ES_OUT_RESET_PCR
);
if
(
stream_Seek
(
p_demux
->
s
,
(
int64_t
)(
i64
*
f
)
)
||
ReSynch
(
p_demux
)
)
return stream_Seek( p_demux->s, (int64_t)(i64 * f) );
{
return
VLC_EGENERIC
;
}
p_sys
->
i_time
=
-
1
;
/* Invalidate time display */
return
VLC_SUCCESS
;
case
DEMUX_GET_TIME
:
case
DEMUX_GET_TIME
:
pi64
=
(
int64_t
*
)
va_arg
(
args
,
int64_t
*
);
pi64
=
(
int64_t
*
)
va_arg
(
args
,
int64_t
*
);
if( p_sys->i_
mux_rate >
0 )
if
(
p_sys
->
i_
time
<
0
)
{
{
*pi64 = (int64_t)1000000 * ( stream_Tell( p_demux->s ) / 50 ) / p_sys->i_mux_rate;
return VLC_SUCCESS;
}
*
pi64
=
0
;
*
pi64
=
0
;
return
VLC_EGENERIC
;
return
VLC_EGENERIC
;
}
*
pi64
=
p_sys
->
i_time
;
return
VLC_SUCCESS
;
#if 0
case DEMUX_GET_LENGTH:
case DEMUX_GET_LENGTH:
pi64 = (int64_t*)va_arg( args, int64_t * );
pi64 = (int64_t*)va_arg( args, int64_t * );
if( p_sys->i_mux_rate > 0 )
if( p_sys->i_mux_rate > 0 )
...
@@ -372,4 +312,166 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
...
@@ -372,4 +312,166 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
}
}
}
}
/*****************************************************************************
* ReSynch:
*****************************************************************************/
static
int
ReSynch
(
demux_t
*
p_demux
)
{
uint8_t
*
p_peek
;
int
i_skip
;
int
i_peek
;
while
(
!
p_demux
->
b_die
)
{
if
(
(
i_peek
=
stream_Peek
(
p_demux
->
s
,
&
p_peek
,
1024
)
)
<
8
)
{
return
VLC_EGENERIC
;
}
i_skip
=
0
;
while
(
i_skip
<
i_peek
-
4
)
{
if
(
!
strncmp
(
p_peek
,
"NSVf"
,
4
)
||
!
strncmp
(
p_peek
,
"NSVs"
,
4
)
)
{
if
(
i_skip
>
0
)
{
stream_Read
(
p_demux
->
s
,
NULL
,
i_skip
);
}
return
VLC_SUCCESS
;
}
p_peek
++
;
i_skip
++
;
}
stream_Read
(
p_demux
->
s
,
NULL
,
i_skip
);
}
return
VLC_EGENERIC
;
}
/*****************************************************************************
* ReadNSVf:
*****************************************************************************/
static
int
ReadNSVf
(
demux_t
*
p_demux
)
{
demux_sys_t
*
p_sys
=
p_demux
->
p_sys
;
uint8_t
*
p
;
int
i_size
;
msg_Dbg
(
p_demux
,
"New NSVf chunk"
);
if
(
stream_Peek
(
p_demux
->
s
,
&
p
,
8
)
<
8
)
{
return
VLC_EGENERIC
;
}
i_size
=
GetDWLE
(
&
p
[
4
]
);
msg_Dbg
(
p_demux
,
" - size=%d"
,
i_size
);
return
stream_Read
(
p_demux
->
s
,
NULL
,
i_size
)
==
i_size
?
VLC_SUCCESS
:
VLC_EGENERIC
;
}
/*****************************************************************************
* ReadNSVf:
*****************************************************************************/
static
int
ReadNSVs
(
demux_t
*
p_demux
)
{
demux_sys_t
*
p_sys
=
p_demux
->
p_sys
;
uint8_t
header
[
19
];
vlc_fourcc_t
fcc
;
if
(
stream_Read
(
p_demux
->
s
,
header
,
19
)
<
19
)
{
msg_Warn
(
p_demux
,
"cannot read"
);
return
VLC_EGENERIC
;
}
msg_Dbg
(
p_demux
,
"New NSVs chunk"
);
/* Video */
switch
(
(
fcc
=
VLC_FOURCC
(
header
[
4
],
header
[
5
],
header
[
6
],
header
[
7
]
)
)
)
{
case
VLC_FOURCC
(
'V'
,
'P'
,
'3'
,
' '
):
case
VLC_FOURCC
(
'V'
,
'P'
,
'3'
,
'1'
):
fcc
=
VLC_FOURCC
(
'V'
,
'P'
,
'3'
,
'1'
);
break
;
case
VLC_FOURCC
(
'N'
,
'O'
,
'N'
,
'E'
):
break
;
default:
msg_Warn
(
p_demux
,
"unknow codec"
);
break
;
}
if
(
fcc
!=
VLC_FOURCC
(
'N'
,
'O'
,
'N'
,
'E'
)
&&
fcc
!=
p_sys
->
fmt_video
.
i_codec
)
{
es_format_Init
(
&
p_sys
->
fmt_video
,
VIDEO_ES
,
fcc
);
p_sys
->
fmt_video
.
video
.
i_width
=
GetWLE
(
&
header
[
12
]
);
p_sys
->
fmt_video
.
video
.
i_height
=
GetWLE
(
&
header
[
14
]
);
if
(
p_sys
->
p_video
)
{
es_out_Del
(
p_demux
->
out
,
p_sys
->
p_video
);
}
p_sys
->
p_video
=
es_out_Add
(
p_demux
->
out
,
&
p_sys
->
fmt_video
);
msg_Dbg
(
p_demux
,
" - video `%4.4s' %dx%d"
,
(
char
*
)
&
fcc
,
p_sys
->
fmt_video
.
video
.
i_width
,
p_sys
->
fmt_video
.
video
.
i_height
);
}
/* Audio */
switch
(
(
fcc
=
VLC_FOURCC
(
header
[
8
],
header
[
9
],
header
[
10
],
header
[
11
]
)
)
)
{
case
VLC_FOURCC
(
'M'
,
'P'
,
'3'
,
' '
):
fcc
=
VLC_FOURCC
(
'm'
,
'p'
,
'g'
,
'a'
);
break
;
case
VLC_FOURCC
(
'P'
,
'C'
,
'M'
,
' '
):
fcc
=
VLC_FOURCC
(
'a'
,
'r'
,
'a'
,
'w'
);
break
;
case
VLC_FOURCC
(
'N'
,
'O'
,
'N'
,
'E'
):
break
;
default:
msg_Warn
(
p_demux
,
"unknow codec"
);
break
;
}
if
(
fcc
!=
VLC_FOURCC
(
'N'
,
'O'
,
'N'
,
'E'
)
&&
fcc
!=
p_sys
->
fmt_audio
.
i_codec
)
{
msg_Dbg
(
p_demux
,
" - audio `%4.4s'"
,
(
char
*
)
&
fcc
);
if
(
p_sys
->
p_audio
)
{
es_out_Del
(
p_demux
->
out
,
p_sys
->
p_audio
);
p_sys
->
p_audio
=
NULL
;
}
es_format_Init
(
&
p_sys
->
fmt_audio
,
AUDIO_ES
,
fcc
);
}
if
(
header
[
16
]
&
0x80
)
{
switch
(
header
[
16
]
&
0x7f
)
{
case
1
:
/* 29.97 fps */
p_sys
->
i_pcr_inc
=
33367
;
break
;
case
3
:
/* 23.976 fps */
p_sys
->
i_pcr_inc
=
41708
;
break
;
case
5
:
/* 14.98 fps */
p_sys
->
i_pcr_inc
=
66755
;
break
;
default:
msg_Dbg
(
p_demux
,
"unknow fps (0x%x)"
,
header
[
16
]
);
p_sys
->
i_pcr_inc
=
40000
;
break
;
}
}
else
if
(
header
[
16
]
!=
0
)
{
p_sys
->
i_pcr_inc
=
1000000
/
header
[
16
];
}
else
{
msg_Dbg
(
p_demux
,
"invalid fps (0x00)"
);
p_sys
->
i_pcr_inc
=
40000
;
}
msg_Dbg
(
p_demux
,
" - fps=%.3f"
,
1000000
.
0
/
(
double
)
p_sys
->
i_pcr_inc
);
return
VLC_SUCCESS
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment