Commit 525de200 authored by Mark Thompson's avatar Mark Thompson

lavc/cbs: Add JPEG support

parent 852c7ba3
......@@ -2273,6 +2273,7 @@ CONFIG_EXTRA="
cbs
cbs_h264
cbs_h265
cbs_jpeg
cbs_mpeg2
cbs_vp9
dirac_parse
......@@ -2536,6 +2537,7 @@ threads_if_any="$THREADS_LIST"
# subsystems
cbs_h264_select="cbs golomb"
cbs_h265_select="cbs golomb"
cbs_jpeg_select="cbs"
cbs_mpeg2_select="cbs"
cbs_vp9_select="cbs"
dct_select="rdft"
......
......@@ -65,6 +65,7 @@ OBJS-$(CONFIG_CABAC) += cabac.o
OBJS-$(CONFIG_CBS) += cbs.o
OBJS-$(CONFIG_CBS_H264) += cbs_h2645.o h2645_parse.o
OBJS-$(CONFIG_CBS_H265) += cbs_h2645.o h2645_parse.o
OBJS-$(CONFIG_CBS_JPEG) += cbs_jpeg.o
OBJS-$(CONFIG_CBS_MPEG2) += cbs_mpeg2.o
OBJS-$(CONFIG_CBS_VP9) += cbs_vp9.o
OBJS-$(CONFIG_CRYSTALHD) += crystalhd.o
......
......@@ -35,6 +35,9 @@ static const CodedBitstreamType *cbs_type_table[] = {
#if CONFIG_CBS_H265
&ff_cbs_type_h265,
#endif
#if CONFIG_CBS_JPEG
&ff_cbs_type_jpeg,
#endif
#if CONFIG_CBS_MPEG2
&ff_cbs_type_mpeg2,
#endif
......@@ -50,6 +53,9 @@ const enum AVCodecID ff_cbs_all_codec_ids[] = {
#if CONFIG_CBS_H265
AV_CODEC_ID_H265,
#endif
#if CONFIG_CBS_JPEG
AV_CODEC_ID_MJPEG,
#endif
#if CONFIG_CBS_MPEG2
AV_CODEC_ID_MPEG2VIDEO,
#endif
......
......@@ -88,6 +88,7 @@ int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
extern const CodedBitstreamType ff_cbs_type_h264;
extern const CodedBitstreamType ff_cbs_type_h265;
extern const CodedBitstreamType ff_cbs_type_jpeg;
extern const CodedBitstreamType ff_cbs_type_mpeg2;
extern const CodedBitstreamType ff_cbs_type_vp9;
......
This diff is collapsed.
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_CBS_JPEG_H
#define AVCODEC_CBS_JPEG_H
#include <stddef.h>
#include <stdint.h>
#include "libavutil/buffer.h"
enum {
JPEG_MARKER_SOF0 = 0xc0,
JPEG_MARKER_SOF1 = 0xc1,
JPEG_MARKER_SOF2 = 0xc2,
JPEG_MARKER_SOF3 = 0xc3,
JPEG_MARKER_DHT = 0xc4,
JPEG_MARKER_SOI = 0xd8,
JPEG_MARKER_EOI = 0xd9,
JPEG_MARKER_SOS = 0xda,
JPEG_MARKER_DQT = 0xdb,
JPEG_MARKER_APPN = 0xe0,
JPEG_MARKER_JPGN = 0xf0,
JPEG_MARKER_COM = 0xfe,
};
enum {
JPEG_MAX_COMPONENTS = 255,
JPEG_MAX_HEIGHT = 65535,
JPEG_MAX_WIDTH = 65535,
};
typedef struct JPEGRawFrameHeader {
uint16_t Lf;
uint8_t P;
uint16_t Y;
uint16_t X;
uint16_t Nf;
uint8_t C [JPEG_MAX_COMPONENTS];
uint8_t H [JPEG_MAX_COMPONENTS];
uint8_t V [JPEG_MAX_COMPONENTS];
uint8_t Tq[JPEG_MAX_COMPONENTS];
} JPEGRawFrameHeader;
typedef struct JPEGRawScanHeader {
uint16_t Ls;
uint8_t Ns;
uint8_t Cs[JPEG_MAX_COMPONENTS];
uint8_t Td[JPEG_MAX_COMPONENTS];
uint8_t Ta[JPEG_MAX_COMPONENTS];
uint8_t Ss;
uint8_t Se;
uint8_t Ah;
uint8_t Al;
} JPEGRawScanHeader;
typedef struct JPEGRawScan {
JPEGRawScanHeader header;
uint8_t *data;
size_t data_size;
AVBufferRef *data_ref;
} JPEGRawScan;
typedef struct JPEGRawQuantisationTable {
uint8_t Pq;
uint8_t Tq;
uint16_t Q[64];
} JPEGRawQuantisationTable;
typedef struct JPEGRawQuantisationTableSpecification {
uint16_t Lq;
JPEGRawQuantisationTable table[4];
} JPEGRawQuantisationTableSpecification;
typedef struct JPEGRawHuffmanTable {
uint8_t Tc;
uint8_t Th;
uint8_t L[16];
uint8_t V[224];
} JPEGRawHuffmanTable;
typedef struct JPEGRawHuffmanTableSpecification {
uint16_t Lh;
JPEGRawHuffmanTable table[8];
} JPEGRawHuffmanTableSpecification;
typedef struct JPEGRawApplicationData {
uint16_t Lp;
uint8_t *Ap;
AVBufferRef *Ap_ref;
} JPEGRawApplicationData;
typedef struct JPEGRawComment {
uint16_t Lc;
uint8_t *Cm;
AVBufferRef *Cm_ref;
} JPEGRawComment;
typedef struct CodedBitstreamJPEGContext {
// Write buffer.
uint8_t *write_buffer;
size_t write_buffer_size;
} CodedBitstreamJPEGContext;
#endif /* AVCODEC_CBS_JPEG_H */
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
static int FUNC(frame_header)(CodedBitstreamContext *ctx, RWContext *rw,
JPEGRawFrameHeader *current)
{
int err, i;
HEADER("Frame Header");
u(16, Lf, 8, 8 + 3 * JPEG_MAX_COMPONENTS);
u(8, P, 2, 16);
u(16, Y, 0, JPEG_MAX_HEIGHT);
u(16, X, 1, JPEG_MAX_WIDTH);
u(8, Nf, 1, JPEG_MAX_COMPONENTS);
for (i = 0; i < current->Nf; i++) {
us(8, C[i], i, 0, JPEG_MAX_COMPONENTS);
us(4, H[i], i, 1, 4);
us(4, V[i], i, 1, 4);
us(8, Tq[i], i, 0, 3);
}
return 0;
}
static int FUNC(quantisation_table)(CodedBitstreamContext *ctx, RWContext *rw,
JPEGRawQuantisationTable *current)
{
int err, i;
u(4, Pq, 0, 1);
u(4, Tq, 0, 3);
if (current->Pq) {
for (i = 0; i < 64; i++)
us(16, Q[i], i, 1, 255);
} else {
for (i = 0; i < 64; i++)
us(8, Q[i], i, 1, 255);
}
return 0;
}
static int FUNC(dqt)(CodedBitstreamContext *ctx, RWContext *rw,
JPEGRawQuantisationTableSpecification *current)
{
int err, i, n;
HEADER("Quantisation Tables");
u(16, Lq, 2, 2 + 4 * 65);
n = current->Lq / 65;
for (i = 0; i < n; i++)
CHECK(FUNC(quantisation_table)(ctx, rw, &current->table[i]));
return 0;
}
static int FUNC(huffman_table)(CodedBitstreamContext *ctx, RWContext *rw,
JPEGRawHuffmanTable *current)
{
int err, i, j, ij;
u(4, Tc, 0, 1);
u(4, Th, 0, 3);
for (i = 0; i < 16; i++)
us(8, L[i], i, 0, 224);
ij = 0;
for (i = 0; i < 16; i++) {
for (j = 0; j < current->L[i]; j++) {
us(8, V[ij], ij, 0, 255);
++ij;
}
}
return 0;
}
static int FUNC(dht)(CodedBitstreamContext *ctx, RWContext *rw,
JPEGRawHuffmanTableSpecification *current)
{
int err, i, j, n;
HEADER("Huffman Tables");
u(16, Lh, 2, 2 + 8 * (1 + 16 + 256));
n = 2;
for (i = 0; n < current->Lh; i++) {
CHECK(FUNC(huffman_table)(ctx, rw, &current->table[i]));
++n;
for (j = 0; j < 16; j++)
n += 1 + current->table[i].L[j];
}
return 0;
}
static int FUNC(scan_header)(CodedBitstreamContext *ctx, RWContext *rw,
JPEGRawScanHeader *current)
{
int err, j;
HEADER("Scan");
u(16, Ls, 6, 6 + 2 * JPEG_MAX_COMPONENTS);
u(8, Ns, 1, 4);
for (j = 0; j < current->Ns; j++) {
us(8, Cs[j], j, 0, JPEG_MAX_COMPONENTS);
us(4, Td[j], j, 0, 3);
us(4, Ta[j], j, 0, 3);
}
u(8, Ss, 0, 63);
u(8, Se, 0, 63);
u(4, Ah, 0, 13);
u(4, Al, 0, 15);
return 0;
}
static int FUNC(application_data)(CodedBitstreamContext *ctx, RWContext *rw,
JPEGRawApplicationData *current)
{
int err, i;
HEADER("Application Data");
u(16, Lp, 2, 65535);
if (current->Lp > 2) {
#ifdef READ
current->Ap_ref = av_buffer_alloc(current->Lp - 2);
if (!current->Ap_ref)
return AVERROR(ENOMEM);
current->Ap = current->Ap_ref->data;
#endif
for (i = 0; i < current->Lp - 2; i++)
us(8, Ap[i], i, 0, 255);
}
return 0;
}
static int FUNC(comment)(CodedBitstreamContext *ctx, RWContext *rw,
JPEGRawComment *current)
{
int err, i;
HEADER("Comment");
u(16, Lc, 2, 65535);
if (current->Lc > 2) {
#ifdef READ
current->Cm_ref = av_buffer_alloc(current->Lc - 2);
if (!current->Cm_ref)
return AVERROR(ENOMEM);
current->Cm = current->Cm_ref->data;
#endif
for (i = 0; i < current->Lc - 2; i++)
us(8, Cm[i], i, 0, 255);
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment