FFmpeg
libavcodec
bsf
hapqa_extract.c
Go to the documentation of this file.
1
/*
2
* HAPQA extract bitstream filter
3
* Copyright (c) 2017 Jokyo Images
4
*
5
* This file is part of FFmpeg.
6
*
7
* FFmpeg is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
11
*
12
* FFmpeg is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
16
*
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with FFmpeg; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
*/
21
22
/**
23
* @file
24
* HAPQA extract bitstream filter
25
* extract one of the two textures of the HAQA
26
*/
27
28
#include "
bsf.h
"
29
#include "
bsf_internal.h
"
30
#include "
bytestream.h
"
31
#include "
hap.h
"
32
33
#include "
libavutil/opt.h
"
34
35
typedef
struct
HapqaExtractContext
{
36
const
AVClass
*
class
;
37
int
texture
;
/* index of the texture to keep (0 for rgb or 1 for alpha) */
38
}
HapqaExtractContext
;
39
40
static
int
check_texture
(
HapqaExtractContext
*
ctx
,
int
section_type) {
41
if
(((
ctx
->texture == 0)&&((section_type & 0x0F) == 0x0F)) ||
/* HapQ texture and rgb extract */
42
((
ctx
->texture == 1)&&((section_type & 0x0F) == 0x01)))
/* HapAlphaOnly texture and alpha extract */
43
{
44
return
1;
/* the texture is the one to keep */
45
}
else
{
46
return
0;
47
}
48
}
49
50
static
int
hapqa_extract
(
AVBSFContext
*bsf,
AVPacket
*
pkt
)
51
{
52
HapqaExtractContext
*
ctx
= bsf->
priv_data
;
53
GetByteContext
gbc;
54
int
section_size;
55
enum
HapSectionType
section_type;
56
int
start_section_size;
57
int
target_packet_size = 0;
58
int
ret
= 0;
59
60
ret
=
ff_bsf_get_packet_ref
(bsf,
pkt
);
61
if
(
ret
< 0)
62
return
ret
;
63
64
bytestream2_init
(&gbc,
pkt
->
data
,
pkt
->
size
);
65
ret
=
ff_hap_parse_section_header
(&gbc, §ion_size, §ion_type);
66
if
(
ret
!= 0)
67
goto
fail
;
68
69
if
((section_type & 0x0F) != 0x0D) {
70
av_log
(bsf,
AV_LOG_ERROR
,
"Invalid section type for HAPQA %#04x.\n"
, section_type & 0x0F);
71
ret
=
AVERROR_INVALIDDATA
;
72
goto
fail
;
73
}
74
75
start_section_size = 4;
76
77
bytestream2_seek
(&gbc, start_section_size, SEEK_SET);
/* go to start of the first texture */
78
79
ret
=
ff_hap_parse_section_header
(&gbc, §ion_size, §ion_type);
80
if
(
ret
!= 0)
81
goto
fail
;
82
83
target_packet_size = section_size + 4;
84
85
if
(
check_texture
(
ctx
, section_type) == 0) {
/* the texture is not the one to keep */
86
start_section_size += 4 + section_size;
87
bytestream2_seek
(&gbc, start_section_size, SEEK_SET);
/* go to start of the second texture */
88
ret
=
ff_hap_parse_section_header
(&gbc, §ion_size, §ion_type);
89
if
(
ret
!= 0)
90
goto
fail
;
91
92
target_packet_size = section_size + 4;
93
94
if
(
check_texture
(
ctx
, section_type) == 0){
/* the second texture is not the one to keep */
95
av_log
(bsf,
AV_LOG_ERROR
,
"No valid texture found.\n"
);
96
ret
=
AVERROR_INVALIDDATA
;
97
goto
fail
;
98
}
99
}
100
101
pkt
->
data
+= start_section_size;
102
pkt
->
size
= target_packet_size;
103
104
fail
:
105
if
(
ret
< 0)
106
av_packet_unref
(
pkt
);
107
return
ret
;
108
}
109
110
static
const
enum
AVCodecID
codec_ids
[] = {
111
AV_CODEC_ID_HAP
,
AV_CODEC_ID_NONE
,
112
};
113
114
#define OFFSET(x) offsetof(HapqaExtractContext, x)
115
#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_BSF_PARAM)
116
static
const
AVOption
options
[] = {
117
{
"texture"
,
"texture to keep"
,
OFFSET
(texture),
AV_OPT_TYPE_INT
, { .i64 = 0 }, 0, 1,
FLAGS
, .unit =
"texture"
},
118
{
"color"
,
"keep HapQ texture"
, 0,
AV_OPT_TYPE_CONST
, { .i64 = 0 }, 0, 0,
FLAGS
, .unit =
"texture"
},
119
{
"alpha"
,
"keep HapAlphaOnly texture"
, 0,
AV_OPT_TYPE_CONST
, { .i64 = 1 }, 0, 0,
FLAGS
, .unit =
"texture"
},
120
{
NULL
},
121
};
122
123
static
const
AVClass
hapqa_extract_class
= {
124
.
class_name
=
"hapqa_extract_bsf"
,
125
.item_name =
av_default_item_name
,
126
.option =
options
,
127
.version =
LIBAVUTIL_VERSION_INT
,
128
};
129
130
const
FFBitStreamFilter
ff_hapqa_extract_bsf
= {
131
.
p
.
name
=
"hapqa_extract"
,
132
.p.codec_ids =
codec_ids
,
133
.p.priv_class = &
hapqa_extract_class
,
134
.priv_data_size =
sizeof
(
HapqaExtractContext
),
135
.
filter
=
hapqa_extract
,
136
};
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition:
packet.c:429
opt.h
bsf_internal.h
GetByteContext
Definition:
bytestream.h:33
AVBitStreamFilter::name
const char * name
Definition:
bsf.h:112
hapqa_extract
static int hapqa_extract(AVBSFContext *bsf, AVPacket *pkt)
Definition:
hapqa_extract.c:50
HapqaExtractContext::texture
int texture
Definition:
hapqa_extract.c:37
bytestream2_seek
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
Definition:
bytestream.h:212
AVPacket::data
uint8_t * data
Definition:
packet.h:539
AVOption
AVOption.
Definition:
opt.h:429
ff_hap_parse_section_header
int ff_hap_parse_section_header(GetByteContext *gbc, int *section_size, enum HapSectionType *section_type)
Definition:
hap.c:58
filter
void(* filter)(uint8_t *src, int stride, int qscale)
Definition:
h263dsp.c:29
AVBSFContext
The bitstream filter state.
Definition:
bsf.h:68
bsf.h
fail
#define fail()
Definition:
checkasm.h:188
hap.h
FLAGS
#define FLAGS
Definition:
hapqa_extract.c:115
pkt
AVPacket * pkt
Definition:
movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition:
log.h:209
ctx
AVFormatContext * ctx
Definition:
movenc.c:49
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition:
version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition:
log.h:75
NULL
#define NULL
Definition:
coverity.c:32
FFBitStreamFilter
Definition:
bsf_internal.h:27
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition:
log.c:237
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition:
codec_id.h:49
FFBitStreamFilter::p
AVBitStreamFilter p
The public AVBitStreamFilter.
Definition:
bsf_internal.h:31
HapSectionType
HapSectionType
Definition:
hap.h:45
AVPacket::size
int size
Definition:
packet.h:540
OFFSET
#define OFFSET(x)
Definition:
hapqa_extract.c:114
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition:
codec_id.h:50
check_texture
static int check_texture(HapqaExtractContext *ctx, int section_type)
Definition:
hapqa_extract.c:40
AVBSFContext::priv_data
void * priv_data
Opaque filter-specific private data.
Definition:
bsf.h:83
ret
ret
Definition:
filter_design.txt:187
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition:
log.h:80
codec_ids
static enum AVCodecID codec_ids[]
Definition:
hapqa_extract.c:110
AV_CODEC_ID_HAP
@ AV_CODEC_ID_HAP
Definition:
codec_id.h:243
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition:
opt.h:259
hapqa_extract_class
static const AVClass hapqa_extract_class
Definition:
hapqa_extract.c:123
options
static const AVOption options[]
Definition:
hapqa_extract.c:116
AVPacket
This structure stores compressed data.
Definition:
packet.h:516
bytestream.h
bytestream2_init
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition:
bytestream.h:137
av_log
#define av_log(a,...)
Definition:
tableprint_vlc.h:27
ff_bsf_get_packet_ref
int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
Called by bitstream filters to get packet for filtering.
Definition:
bsf.c:256
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition:
error.h:61
HapqaExtractContext
Definition:
hapqa_extract.c:35
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition:
opt.h:299
ff_hapqa_extract_bsf
const FFBitStreamFilter ff_hapqa_extract_bsf
Definition:
hapqa_extract.c:130
Generated on Thu Nov 14 2024 19:21:33 for FFmpeg by
1.8.17