61#define JPEGAPP_MAX_RECORD (16 * 1024 * 1024)
102 if (!
s->filename || !
s->filename[0]) {
138 got = fread(hdr, 1, 4,
s->file);
140 if (got == 0 && feof(
s->file) && !ferror(
s->file)) {
142 "jpegapp: no sidecar record for packet %"PRId64
"\n",
147 if (ferror(
s->file)) {
159 if (n > (uint32_t)
s->buf_size) {
169 got = fread(
s->buf, 1, n,
s->file);
172 if (ferror(
s->file)) {
182 "jpegapp: payload is not a sequence of APP0..APP15 segments\n");
194 int rec_size = 0, src_off, dst_size, ret;
216 if (rec_size >= 2 &&
s->buf[0] == 0xff &&
s->buf[1] ==
APP0 &&
221 "jpegapp: existing APP0 is invalid or truncated\n");
233 if (in->
size - src_off > INT_MAX - 2 - rec_size) {
237 dst_size = 2 + rec_size + (in->
size - src_off);
245 memcpy(
out->data, in->
data, 2);
246 memcpy(
out->data + 2,
s->buf, rec_size);
247 memcpy(
out->data + 2 + rec_size, in->
data + src_off, in->
size - src_off);
258#define OFFSET(x) offsetof(JPEGAppContext, x)
259#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_BSF_PARAM)
261 {
"filename",
"sidecar of u32be-length + APP-segment records",
OFFSET(filename),
263 {
"file",
"sidecar of u32be-length + APP-segment records",
OFFSET(filename),
269 .class_name =
"jpegapp",
static AVFormatContext * ctx
static av_cold void close(AVCodecParserContext *s)
const FFBitStreamFilter ff_jpegapp_bsf
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt)
Called by the bitstream filters to get the next packet for filtering.
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
AVCodecID
Identify the syntax and semantics of the bitstream.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
Copy only "properties" fields from src to dst.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
#define LIBAVUTIL_VERSION_INT
static int jpegapp_init(AVBSFContext *ctx)
static int jpegapp_read_record(AVBSFContext *ctx, int *out_size)
#define JPEGAPP_MAX_RECORD
Sidecar format (big-endian), one record per encoded JPEG packet:
static int jpegapp_filter(AVBSFContext *ctx, AVPacket *out)
static const AVClass jpegapp_class
static int jpeg_app_segment_len(const uint8_t *data, int size)
static int jpegapp_validate_payload(const uint8_t *data, int size)
static const AVOption jpegapp_options[]
static enum AVCodecID jpegapp_codec_ids[]
static void jpegapp_close(AVBSFContext *ctx)
FILE * avpriv_fopen_utf8(const char *path, const char *mode)
Open a file using a UTF-8 filename.
Memory handling functions.
MJPEG encoder and decoder.
The bitstream filter state.
Describe the class of an AVClass context structure.
This structure stores compressed data.
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)