Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
e52788d0
Commit
e52788d0
authored
Apr 04, 2004
by
Michael Niedermayer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
info packet read/write & simplify
Originally committed as revision 2965 to
svn://svn.ffmpeg.org/ffmpeg/trunk
parent
ae3fa4ea
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
57 deletions
+106
-57
nut.c
libavformat/nut.c
+106
-57
No files found.
libavformat/nut.c
View file @
e52788d0
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
* - checksumming
* - checksumming
* - seeking
* - seeking
* - index writing
* - index writing
* - in
fo and in
dex packet reading support
* - index packet reading support
* - startcode searching for broken streams
* - startcode searching for broken streams
*/
*/
...
@@ -94,6 +94,26 @@ typedef struct {
...
@@ -94,6 +94,26 @@ typedef struct {
StreamContext
*
stream
;
StreamContext
*
stream
;
}
NUTContext
;
}
NUTContext
;
static
char
*
info_table
[][
2
]
=
{
{
NULL
,
NULL
},
// end
{
NULL
,
NULL
},
{
NULL
,
"UTF8"
},
{
NULL
,
"v"
},
{
NULL
,
"s"
},
{
"StreamId"
,
"v"
},
{
"SegmentId"
,
"v"
},
{
"StartTimestamp"
,
"v"
},
{
"EndTimestamp"
,
"v"
},
{
"Author"
,
"UTF8"
},
{
"Titel"
,
"UTF8"
},
{
"Description"
,
"UTF8"
},
{
"Copyright"
,
"UTF8"
},
{
"Encoder"
,
"UTF8"
},
{
"Keyword"
,
"UTF8"
},
{
"Cover"
,
"JPEG"
},
{
"Cover"
,
"PNG"
},
};
static
void
update_lru
(
int
*
lru
,
int
current
,
int
count
){
static
void
update_lru
(
int
*
lru
,
int
current
,
int
count
){
int
i
;
int
i
;
...
@@ -245,30 +265,23 @@ static uint64_t get_v(ByteIOContext *bc)
...
@@ -245,30 +265,23 @@ static uint64_t get_v(ByteIOContext *bc)
return
-
1
;
return
-
1
;
}
}
static
int
get_b
(
ByteIOContext
*
bc
,
char
*
data
,
int
maxlen
)
static
int
get_str
(
ByteIOContext
*
bc
,
char
*
string
,
int
maxlen
){
{
int
len
=
get_v
(
bc
);
int
i
,
len
;
len
=
get_v
(
bc
);
if
(
len
&&
maxlen
)
for
(
i
=
0
;
i
<
len
&&
i
<
maxlen
;
i
++
)
get_buffer
(
bc
,
string
,
FFMIN
(
len
,
maxlen
));
data
[
i
]
=
get_byte
(
bc
);
while
(
len
>
maxlen
){
/* skip remaining bytes */
get_byte
(
bc
);
url_fskip
(
bc
,
len
-
i
);
len
--
;
}
return
0
;
}
static
int
get_bi
(
ByteIOContext
*
bc
)
if
(
maxlen
)
{
string
[
FFMIN
(
len
,
maxlen
-
1
)]
=
0
;
int
i
,
len
,
val
=
0
;
len
=
get_v
(
bc
);
if
(
maxlen
==
len
)
for
(
i
=
0
;
i
<
len
&&
i
<=
4
;
i
++
)
return
-
1
;
val
|=
get_byte
(
bc
)
<<
(
i
*
8
);
else
/* skip remaining bytes */
return
0
;
url_fskip
(
bc
,
len
-
i
);
return
val
;
}
}
static
int
get_packetheader
(
NUTContext
*
nut
,
ByteIOContext
*
bc
,
int
prefix_length
)
static
int
get_packetheader
(
NUTContext
*
nut
,
ByteIOContext
*
bc
,
int
prefix_length
)
...
@@ -330,21 +343,12 @@ static int put_v(ByteIOContext *bc, uint64_t val)
...
@@ -330,21 +343,12 @@ static int put_v(ByteIOContext *bc, uint64_t val)
return
0
;
return
0
;
}
}
static
int
put_b
(
ByteIOContext
*
bc
,
char
*
data
,
int
len
)
static
int
put_str
(
ByteIOContext
*
bc
,
const
char
*
string
){
{
int
len
=
strlen
(
string
);
int
i
;
put_v
(
bc
,
len
);
put_v
(
bc
,
len
);
for
(
i
=
0
;
i
<
len
;
i
++
)
put_buffer
(
bc
,
string
,
len
);
put_byte
(
bc
,
data
[
i
]);
return
0
;
}
static
int
put_bi
(
ByteIOContext
*
bc
,
int
val
)
{
put_v
(
bc
,
4
);
put_le32
(
bc
,
val
);
return
0
;
return
0
;
}
}
...
@@ -447,17 +451,17 @@ static int nut_write_header(AVFormatContext *s)
...
@@ -447,17 +451,17 @@ static int nut_write_header(AVFormatContext *s)
put_v
(
bc
,
i
/*s->streams[i]->index*/
);
put_v
(
bc
,
i
/*s->streams[i]->index*/
);
put_v
(
bc
,
(
codec
->
codec_type
==
CODEC_TYPE_AUDIO
)
?
32
:
0
);
put_v
(
bc
,
(
codec
->
codec_type
==
CODEC_TYPE_AUDIO
)
?
32
:
0
);
if
(
codec
->
codec_tag
)
if
(
codec
->
codec_tag
)
put_
bi
(
bc
,
codec
->
codec_tag
);
put_
v
(
bc
,
codec
->
codec_tag
);
else
if
(
codec
->
codec_type
==
CODEC_TYPE_VIDEO
)
else
if
(
codec
->
codec_type
==
CODEC_TYPE_VIDEO
)
{
{
int
tmp
=
codec_get_bmp_tag
(
codec
->
codec_id
);
put_v
(
bc
,
codec_get_bmp_tag
(
codec
->
codec_id
));
put_bi
(
bc
,
tmp
);
}
}
else
if
(
codec
->
codec_type
==
CODEC_TYPE_AUDIO
)
else
if
(
codec
->
codec_type
==
CODEC_TYPE_AUDIO
)
{
{
int
tmp
=
codec_get_wav_tag
(
codec
->
codec_id
);
put_v
(
bc
,
codec_get_wav_tag
(
codec
->
codec_id
));
put_bi
(
bc
,
tmp
);
}
}
else
put_v
(
bc
,
0
);
if
(
codec
->
codec_type
==
CODEC_TYPE_VIDEO
)
if
(
codec
->
codec_type
==
CODEC_TYPE_VIDEO
)
{
{
...
@@ -520,40 +524,38 @@ static int nut_write_header(AVFormatContext *s)
...
@@ -520,40 +524,38 @@ static int nut_write_header(AVFormatContext *s)
update_packetheader
(
nut
,
bc
,
0
);
update_packetheader
(
nut
,
bc
,
0
);
}
}
#if 0
/* info header */
/* info header */
put_be64
(
bc
,
INFO_STARTCODE
);
put_be64
(
bc
,
INFO_STARTCODE
);
put_packetheader(nut, bc,
16
+strlen(s->author)+strlen(s->title)+
put_packetheader
(
nut
,
bc
,
30
+
strlen
(
s
->
author
)
+
strlen
(
s
->
title
)
+
strlen(s->comment)+strlen(s->copyright));
strlen
(
s
->
comment
)
+
strlen
(
s
->
copyright
)
+
strlen
(
LIBAVFORMAT_IDENT
)
);
if
(
s
->
author
[
0
])
if
(
s
->
author
[
0
])
{
{
put_v(bc,
5
); /* type */
put_v
(
bc
,
9
);
/* type */
put_
b(bc, s->author, strlen(s->author)
);
put_
str
(
bc
,
s
->
author
);
}
}
if
(
s
->
title
[
0
])
if
(
s
->
title
[
0
])
{
{
put_v(bc,
6
); /* type */
put_v
(
bc
,
10
);
/* type */
put_
b(bc, s->title, strlen(s->title)
);
put_
str
(
bc
,
s
->
title
);
}
}
if
(
s
->
comment
[
0
])
if
(
s
->
comment
[
0
])
{
{
put_v(bc,
7
); /* type */
put_v
(
bc
,
11
);
/* type */
put_
b(bc, s->comment, strlen(s->comment)
);
put_
str
(
bc
,
s
->
comment
);
}
}
if
(
s
->
copyright
[
0
])
if
(
s
->
copyright
[
0
])
{
{
put_v(bc,
8
); /* type */
put_v
(
bc
,
12
);
/* type */
put_
b(bc, s->copyright, strlen(s->copyright)
);
put_
str
(
bc
,
s
->
copyright
);
}
}
/* encoder */
/* encoder */
put_v(bc,
9
); /* type */
put_v
(
bc
,
13
);
/* type */
put_
b(bc, LIBAVFORMAT_IDENT "\0", strlen(LIBAVFORMAT_IDENT)
);
put_
str
(
bc
,
LIBAVFORMAT_IDENT
);
put_v
(
bc
,
0
);
/* eof info */
put_v
(
bc
,
0
);
/* eof info */
put_be32
(
bc
,
0
);
/* FIXME: checksum */
put_be32
(
bc
,
0
);
/* FIXME: checksum */
update_packetheader
(
nut
,
bc
,
0
);
update_packetheader
(
nut
,
bc
,
0
);
#endif
put_flush_packet
(
bc
);
put_flush_packet
(
bc
);
...
@@ -839,7 +841,7 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
...
@@ -839,7 +841,7 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
if
(
!
st
)
if
(
!
st
)
return
AVERROR_NOMEM
;
return
AVERROR_NOMEM
;
class
=
get_v
(
bc
);
class
=
get_v
(
bc
);
tmp
=
get_
bi
(
bc
);
tmp
=
get_
v
(
bc
);
switch
(
class
)
switch
(
class
)
{
{
case
0
:
case
0
:
...
@@ -859,7 +861,7 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
...
@@ -859,7 +861,7 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
return
-
1
;
return
-
1
;
}
}
s
->
bit_rate
+=
get_v
(
bc
);
s
->
bit_rate
+=
get_v
(
bc
);
get_
b
(
bc
,
NULL
,
0
);
/* language code */
get_
v
(
bc
);
/* language code */
nom
=
get_v
(
bc
);
nom
=
get_v
(
bc
);
denom
=
get_v
(
bc
);
denom
=
get_v
(
bc
);
nut
->
stream
[
cur_stream
].
msb_timestamp_shift
=
get_v
(
bc
);
nut
->
stream
[
cur_stream
].
msb_timestamp_shift
=
get_v
(
bc
);
...
@@ -896,7 +898,54 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
...
@@ -896,7 +898,54 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
get_be32
(
bc
);
/* checksum */
get_be32
(
bc
);
/* checksum */
nut
->
stream
[
cur_stream
].
rate_num
=
nom
;
nut
->
stream
[
cur_stream
].
rate_num
=
nom
;
nut
->
stream
[
cur_stream
].
rate_den
=
denom
;
nut
->
stream
[
cur_stream
].
rate_den
=
denom
;
}
}
tmp
=
get_be64
(
bc
);
if
(
tmp
==
INFO_STARTCODE
){
get_packetheader
(
nut
,
bc
,
8
);
for
(;;){
int
id
=
get_v
(
bc
);
char
*
name
,
*
type
,
custom_name
[
256
],
custom_type
[
256
];
if
(
!
id
)
break
;
else
if
(
id
>=
sizeof
(
info_table
)
/
sizeof
(
info_table
[
0
])){
av_log
(
s
,
AV_LOG_ERROR
,
"info id is too large %d %d
\n
"
,
id
,
sizeof
(
info_table
)
/
sizeof
(
info_table
[
0
]));
return
-
1
;
}
type
=
info_table
[
id
][
1
];
name
=
info_table
[
id
][
0
];
//av_log(s, AV_LOG_DEBUG, "%d %s %s\n", id, type, name);
if
(
!
type
){
get_str
(
bc
,
custom_type
,
sizeof
(
custom_type
));
type
=
custom_type
;
}
if
(
!
name
){
get_str
(
bc
,
custom_name
,
sizeof
(
custom_name
));
name
=
custom_name
;
}
if
(
!
strcmp
(
type
,
"v"
)){
int
value
=
get_v
(
bc
);
}
else
{
if
(
!
strcmp
(
name
,
"Author"
))
get_str
(
bc
,
s
->
author
,
sizeof
(
s
->
author
));
else
if
(
!
strcmp
(
name
,
"Title"
))
get_str
(
bc
,
s
->
title
,
sizeof
(
s
->
title
));
else
if
(
!
strcmp
(
name
,
"Copyright"
))
get_str
(
bc
,
s
->
copyright
,
sizeof
(
s
->
copyright
));
else
if
(
!
strcmp
(
name
,
"Description"
))
get_str
(
bc
,
s
->
comment
,
sizeof
(
s
->
comment
));
else
get_str
(
bc
,
NULL
,
0
);
}
}
get_be32
(
bc
);
/* checksum */
}
else
url_fseek
(
bc
,
-
8
,
SEEK_CUR
);
return
0
;
return
0
;
}
}
...
...
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