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
381a4e31
Commit
381a4e31
authored
Apr 13, 2016
by
Alexandra Hájková
Committed by
Diego Biurrun
Jan 25, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tak: Convert to the new bitstream reader
parent
2e0e1501
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
125 additions
and
120 deletions
+125
-120
tak.c
libavcodec/tak.c
+25
-24
tak.h
libavcodec/tak.h
+5
-5
tak_parser.c
libavcodec/tak_parser.c
+8
-7
takdec.c
libavcodec/takdec.c
+80
-78
takdec.c
libavformat/takdec.c
+7
-6
No files found.
libavcodec/tak.c
View file @
381a4e31
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include "libavutil/intreadwrite.h"
#include "libavutil/intreadwrite.h"
#define BITSTREAM_READER_LE
#define BITSTREAM_READER_LE
#include "bitstream.h"
#include "tak.h"
#include "tak.h"
static
const
uint16_t
frame_duration_type_quants
[]
=
{
static
const
uint16_t
frame_duration_type_quants
[]
=
{
...
@@ -85,30 +86,30 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size)
...
@@ -85,30 +86,30 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size)
return
0
;
return
0
;
}
}
void
avpriv_tak_parse_streaminfo
(
GetBitContext
*
gb
,
TAKStreamInfo
*
s
)
void
avpriv_tak_parse_streaminfo
(
BitstreamContext
*
bc
,
TAKStreamInfo
*
s
)
{
{
uint64_t
channel_mask
=
0
;
uint64_t
channel_mask
=
0
;
int
frame_type
,
i
;
int
frame_type
,
i
;
s
->
codec
=
get_bits
(
gb
,
TAK_ENCODER_CODEC_BITS
);
s
->
codec
=
bitstream_read
(
bc
,
TAK_ENCODER_CODEC_BITS
);
skip_bits
(
gb
,
TAK_ENCODER_PROFILE_BITS
);
bitstream_skip
(
bc
,
TAK_ENCODER_PROFILE_BITS
);
frame_type
=
get_bits
(
gb
,
TAK_SIZE_FRAME_DURATION_BITS
);
frame_type
=
bitstream_read
(
bc
,
TAK_SIZE_FRAME_DURATION_BITS
);
s
->
samples
=
get_bits64
(
gb
,
TAK_SIZE_SAMPLES_NUM_BITS
);
s
->
samples
=
bitstream_read_63
(
bc
,
TAK_SIZE_SAMPLES_NUM_BITS
);
s
->
data_type
=
get_bits
(
gb
,
TAK_FORMAT_DATA_TYPE_BITS
);
s
->
data_type
=
bitstream_read
(
bc
,
TAK_FORMAT_DATA_TYPE_BITS
);
s
->
sample_rate
=
get_bits
(
gb
,
TAK_FORMAT_SAMPLE_RATE_BITS
)
+
s
->
sample_rate
=
bitstream_read
(
bc
,
TAK_FORMAT_SAMPLE_RATE_BITS
)
+
TAK_SAMPLE_RATE_MIN
;
TAK_SAMPLE_RATE_MIN
;
s
->
bps
=
get_bits
(
gb
,
TAK_FORMAT_BPS_BITS
)
+
s
->
bps
=
bitstream_read
(
bc
,
TAK_FORMAT_BPS_BITS
)
+
TAK_BPS_MIN
;
TAK_BPS_MIN
;
s
->
channels
=
get_bits
(
gb
,
TAK_FORMAT_CHANNEL_BITS
)
+
s
->
channels
=
bitstream_read
(
bc
,
TAK_FORMAT_CHANNEL_BITS
)
+
TAK_CHANNELS_MIN
;
TAK_CHANNELS_MIN
;
if
(
get_bits1
(
gb
))
{
if
(
bitstream_read_bit
(
bc
))
{
skip_bits
(
gb
,
TAK_FORMAT_VALID_BITS
);
bitstream_skip
(
bc
,
TAK_FORMAT_VALID_BITS
);
if
(
get_bits1
(
gb
))
{
if
(
bitstream_read_bit
(
bc
))
{
for
(
i
=
0
;
i
<
s
->
channels
;
i
++
)
{
for
(
i
=
0
;
i
<
s
->
channels
;
i
++
)
{
int
value
=
get_bits
(
gb
,
TAK_FORMAT_CH_LAYOUT_BITS
);
int
value
=
bitstream_read
(
bc
,
TAK_FORMAT_CH_LAYOUT_BITS
);
if
(
value
>
0
&&
value
<=
18
)
if
(
value
>
0
&&
value
<=
18
)
channel_mask
|=
1
<<
(
value
-
1
);
channel_mask
|=
1
<<
(
value
-
1
);
...
@@ -120,33 +121,33 @@ void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s)
...
@@ -120,33 +121,33 @@ void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s)
s
->
frame_samples
=
tak_get_nb_samples
(
s
->
sample_rate
,
frame_type
);
s
->
frame_samples
=
tak_get_nb_samples
(
s
->
sample_rate
,
frame_type
);
}
}
int
ff_tak_decode_frame_header
(
AVCodecContext
*
avctx
,
GetBitContext
*
gb
,
int
ff_tak_decode_frame_header
(
AVCodecContext
*
avctx
,
BitstreamContext
*
bc
,
TAKStreamInfo
*
ti
,
int
log_level_offset
)
TAKStreamInfo
*
ti
,
int
log_level_offset
)
{
{
if
(
get_bits
(
gb
,
TAK_FRAME_HEADER_SYNC_ID_BITS
)
!=
TAK_FRAME_HEADER_SYNC_ID
)
{
if
(
bitstream_read
(
bc
,
TAK_FRAME_HEADER_SYNC_ID_BITS
)
!=
TAK_FRAME_HEADER_SYNC_ID
)
{
av_log
(
avctx
,
AV_LOG_ERROR
+
log_level_offset
,
"missing sync id
\n
"
);
av_log
(
avctx
,
AV_LOG_ERROR
+
log_level_offset
,
"missing sync id
\n
"
);
return
AVERROR_INVALIDDATA
;
return
AVERROR_INVALIDDATA
;
}
}
ti
->
flags
=
get_bits
(
gb
,
TAK_FRAME_HEADER_FLAGS_BITS
);
ti
->
flags
=
bitstream_read
(
bc
,
TAK_FRAME_HEADER_FLAGS_BITS
);
ti
->
frame_num
=
get_bits
(
gb
,
TAK_FRAME_HEADER_NO_BITS
);
ti
->
frame_num
=
bitstream_read
(
bc
,
TAK_FRAME_HEADER_NO_BITS
);
if
(
ti
->
flags
&
TAK_FRAME_FLAG_IS_LAST
)
{
if
(
ti
->
flags
&
TAK_FRAME_FLAG_IS_LAST
)
{
ti
->
last_frame_samples
=
get_bits
(
gb
,
TAK_FRAME_HEADER_SAMPLE_COUNT_BITS
)
+
1
;
ti
->
last_frame_samples
=
bitstream_read
(
bc
,
TAK_FRAME_HEADER_SAMPLE_COUNT_BITS
)
+
1
;
skip_bits
(
gb
,
2
);
bitstream_skip
(
bc
,
2
);
}
else
{
}
else
{
ti
->
last_frame_samples
=
0
;
ti
->
last_frame_samples
=
0
;
}
}
if
(
ti
->
flags
&
TAK_FRAME_FLAG_HAS_INFO
)
{
if
(
ti
->
flags
&
TAK_FRAME_FLAG_HAS_INFO
)
{
avpriv_tak_parse_streaminfo
(
gb
,
ti
);
avpriv_tak_parse_streaminfo
(
bc
,
ti
);
if
(
get_bits
(
gb
,
6
))
if
(
bitstream_read
(
bc
,
6
))
skip_bits
(
gb
,
25
);
bitstream_skip
(
bc
,
25
);
align_get_bits
(
gb
);
bitstream_align
(
bc
);
}
}
skip_bits
(
gb
,
24
);
bitstream_skip
(
bc
,
24
);
return
0
;
return
0
;
}
}
libavcodec/tak.h
View file @
381a4e31
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
#include <stdint.h>
#include <stdint.h>
#include "avcodec.h"
#include "avcodec.h"
#include "
get_bits
.h"
#include "
bitstream
.h"
#define TAK_FORMAT_DATA_TYPE_BITS 3
#define TAK_FORMAT_DATA_TYPE_BITS 3
#define TAK_FORMAT_SAMPLE_RATE_BITS 18
#define TAK_FORMAT_SAMPLE_RATE_BITS 18
...
@@ -145,21 +145,21 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size);
...
@@ -145,21 +145,21 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size);
/**
/**
* Parse the Streaminfo metadata block.
* Parse the Streaminfo metadata block.
* @param[in]
gb pointer to GetBit
Context
* @param[in]
bc pointer to Bitstream
Context
* @param[out] s storage for parsed information
* @param[out] s storage for parsed information
*/
*/
void
avpriv_tak_parse_streaminfo
(
GetBitContext
*
gb
,
TAKStreamInfo
*
s
);
void
avpriv_tak_parse_streaminfo
(
BitstreamContext
*
bc
,
TAKStreamInfo
*
s
);
/**
/**
* Validate and decode a frame header.
* Validate and decode a frame header.
* @param avctx AVCodecContext to use as av_log() context
* @param avctx AVCodecContext to use as av_log() context
* @param[in]
gb GetBit
Context from which to read frame header
* @param[in]
bc Bitstream
Context from which to read frame header
* @param[out] s frame information
* @param[out] s frame information
* @param log_level_offset log level offset, can be used to silence
* @param log_level_offset log level offset, can be used to silence
* error messages.
* error messages.
* @return non-zero on error, 0 if OK
* @return non-zero on error, 0 if OK
*/
*/
int
ff_tak_decode_frame_header
(
AVCodecContext
*
avctx
,
GetBitContext
*
gb
,
int
ff_tak_decode_frame_header
(
AVCodecContext
*
avctx
,
BitstreamContext
*
bc
,
TAKStreamInfo
*
s
,
int
log_level_offset
);
TAKStreamInfo
*
s
,
int
log_level_offset
);
#endif
/* AVCODEC_TAK_H */
#endif
/* AVCODEC_TAK_H */
libavcodec/tak_parser.c
View file @
381a4e31
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
**/
**/
#define BITSTREAM_READER_LE
#define BITSTREAM_READER_LE
#include "bitstream.h"
#include "parser.h"
#include "parser.h"
#include "tak.h"
#include "tak.h"
...
@@ -47,14 +48,14 @@ static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,
...
@@ -47,14 +48,14 @@ static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,
TAKParseContext
*
t
=
s
->
priv_data
;
TAKParseContext
*
t
=
s
->
priv_data
;
ParseContext
*
pc
=
&
t
->
pc
;
ParseContext
*
pc
=
&
t
->
pc
;
int
next
=
END_NOT_FOUND
;
int
next
=
END_NOT_FOUND
;
GetBitContext
gb
;
BitstreamContext
bc
;
int
consumed
=
0
;
int
consumed
=
0
;
int
needed
=
buf_size
?
TAK_MAX_FRAME_HEADER_BYTES
:
8
;
int
needed
=
buf_size
?
TAK_MAX_FRAME_HEADER_BYTES
:
8
;
if
(
s
->
flags
&
PARSER_FLAG_COMPLETE_FRAMES
)
{
if
(
s
->
flags
&
PARSER_FLAG_COMPLETE_FRAMES
)
{
TAKStreamInfo
ti
;
TAKStreamInfo
ti
;
init_get_bits
(
&
gb
,
buf
,
buf_size
);
bitstream_init
(
&
bc
,
buf
,
buf_size
);
if
(
!
ff_tak_decode_frame_header
(
avctx
,
&
gb
,
&
ti
,
127
))
if
(
!
ff_tak_decode_frame_header
(
avctx
,
&
bc
,
&
ti
,
127
))
s
->
duration
=
t
->
ti
.
last_frame_samples
?
t
->
ti
.
last_frame_samples
s
->
duration
=
t
->
ti
.
last_frame_samples
?
t
->
ti
.
last_frame_samples
:
t
->
ti
.
frame_samples
;
:
t
->
ti
.
frame_samples
;
*
poutbuf
=
buf
;
*
poutbuf
=
buf
;
...
@@ -79,14 +80,14 @@ static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,
...
@@ -79,14 +80,14 @@ static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,
pc
->
buffer
[
t
->
index
+
1
]
==
0xA0
)
{
pc
->
buffer
[
t
->
index
+
1
]
==
0xA0
)
{
TAKStreamInfo
ti
;
TAKStreamInfo
ti
;
init_get_bits
(
&
gb
,
pc
->
buffer
+
t
->
index
,
bitstream_init8
(
&
bc
,
pc
->
buffer
+
t
->
index
,
8
*
(
pc
->
index
-
t
->
index
)
);
pc
->
index
-
t
->
index
);
if
(
!
ff_tak_decode_frame_header
(
avctx
,
&
gb
,
if
(
!
ff_tak_decode_frame_header
(
avctx
,
&
bc
,
pc
->
frame_start_found
?
&
ti
pc
->
frame_start_found
?
&
ti
:
&
t
->
ti
,
:
&
t
->
ti
,
127
)
&&
127
)
&&
!
ff_tak_check_crc
(
pc
->
buffer
+
t
->
index
,
!
ff_tak_check_crc
(
pc
->
buffer
+
t
->
index
,
get_bits_count
(
&
gb
)
/
8
))
{
bitstream_tell
(
&
bc
)
/
8
))
{
if
(
!
pc
->
frame_start_found
)
{
if
(
!
pc
->
frame_start_found
)
{
pc
->
frame_start_found
=
1
;
pc
->
frame_start_found
=
1
;
s
->
duration
=
t
->
ti
.
last_frame_samples
?
s
->
duration
=
t
->
ti
.
last_frame_samples
?
...
...
libavcodec/takdec.c
View file @
381a4e31
This diff is collapsed.
Click to expand it.
libavformat/takdec.c
View file @
381a4e31
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
*/
*/
#define BITSTREAM_READER_LE
#define BITSTREAM_READER_LE
#include "libavcodec/bitstream.h"
#include "libavcodec/tak.h"
#include "libavcodec/tak.h"
#include "apetag.h"
#include "apetag.h"
...
@@ -43,7 +44,7 @@ static int tak_read_header(AVFormatContext *s)
...
@@ -43,7 +44,7 @@ static int tak_read_header(AVFormatContext *s)
{
{
TAKDemuxContext
*
tc
=
s
->
priv_data
;
TAKDemuxContext
*
tc
=
s
->
priv_data
;
AVIOContext
*
pb
=
s
->
pb
;
AVIOContext
*
pb
=
s
->
pb
;
GetBitContext
gb
;
BitstreamContext
bc
;
AVStream
*
st
;
AVStream
*
st
;
uint8_t
*
buffer
=
NULL
;
uint8_t
*
buffer
=
NULL
;
int
ret
;
int
ret
;
...
@@ -82,7 +83,7 @@ static int tak_read_header(AVFormatContext *s)
...
@@ -82,7 +83,7 @@ static int tak_read_header(AVFormatContext *s)
return
AVERROR
(
EIO
);
return
AVERROR
(
EIO
);
}
}
init_get_bits
(
&
gb
,
buffer
,
size
*
8
);
bitstream_init8
(
&
bc
,
buffer
,
size
);
break
;
break
;
case
TAK_METADATA_MD5
:
{
case
TAK_METADATA_MD5
:
{
uint8_t
md5
[
16
];
uint8_t
md5
[
16
];
...
@@ -118,7 +119,7 @@ static int tak_read_header(AVFormatContext *s)
...
@@ -118,7 +119,7 @@ static int tak_read_header(AVFormatContext *s)
if
(
type
==
TAK_METADATA_STREAMINFO
)
{
if
(
type
==
TAK_METADATA_STREAMINFO
)
{
TAKStreamInfo
ti
;
TAKStreamInfo
ti
;
avpriv_tak_parse_streaminfo
(
&
gb
,
&
ti
);
avpriv_tak_parse_streaminfo
(
&
bc
,
&
ti
);
if
(
ti
.
samples
>
0
)
if
(
ti
.
samples
>
0
)
st
->
duration
=
ti
.
samples
;
st
->
duration
=
ti
.
samples
;
st
->
codecpar
->
bits_per_coded_sample
=
ti
.
bps
;
st
->
codecpar
->
bits_per_coded_sample
=
ti
.
bps
;
...
@@ -135,12 +136,12 @@ static int tak_read_header(AVFormatContext *s)
...
@@ -135,12 +136,12 @@ static int tak_read_header(AVFormatContext *s)
if
(
size
!=
11
)
if
(
size
!=
11
)
return
AVERROR_INVALIDDATA
;
return
AVERROR_INVALIDDATA
;
tc
->
mlast_frame
=
1
;
tc
->
mlast_frame
=
1
;
tc
->
data_end
=
get_bits64
(
&
gb
,
TAK_LAST_FRAME_POS_BITS
)
+
tc
->
data_end
=
bitstream_read_63
(
&
bc
,
TAK_LAST_FRAME_POS_BITS
)
+
get_bits
(
&
gb
,
TAK_LAST_FRAME_SIZE_BITS
);
bitstream_read
(
&
bc
,
TAK_LAST_FRAME_SIZE_BITS
);
av_freep
(
&
buffer
);
av_freep
(
&
buffer
);
}
else
if
(
type
==
TAK_METADATA_ENCODER
)
{
}
else
if
(
type
==
TAK_METADATA_ENCODER
)
{
av_log
(
s
,
AV_LOG_VERBOSE
,
"encoder version: %0X
\n
"
,
av_log
(
s
,
AV_LOG_VERBOSE
,
"encoder version: %0X
\n
"
,
get_bits_long
(
&
gb
,
TAK_ENCODER_VERSION_BITS
));
bitstream_read
(
&
bc
,
TAK_ENCODER_VERSION_BITS
));
av_freep
(
&
buffer
);
av_freep
(
&
buffer
);
}
}
}
}
...
...
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