Commit dd1e5bfd authored by anatoly's avatar anatoly Committed by Michael Niedermayer

Add support for picture_ptr field in MJpegDecodeContext

Signed-off-by: 's avatarAnton Khirnov <anton@khirnov.net>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 7e6a9e64
...@@ -129,7 +129,7 @@ read_header: ...@@ -129,7 +129,7 @@ read_header:
//XXX FIXME factorize, this looks very similar to the EOI code //XXX FIXME factorize, this looks very similar to the EOI code
*picture= s->picture; *picture= *s->picture_ptr;
*data_size = sizeof(AVFrame); *data_size = sizeof(AVFrame);
if(!s->lossless){ if(!s->lossless){
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <assert.h> #include <assert.h>
#include "libavutil/imgutils.h" #include "libavutil/imgutils.h"
#include "libavutil/avassert.h"
#include "avcodec.h" #include "avcodec.h"
#include "dsputil.h" #include "dsputil.h"
#include "mjpeg.h" #include "mjpeg.h"
...@@ -81,6 +82,9 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) ...@@ -81,6 +82,9 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
{ {
MJpegDecodeContext *s = avctx->priv_data; MJpegDecodeContext *s = avctx->priv_data;
if (!s->picture_ptr)
s->picture_ptr = &s->picture;
s->avctx = avctx; s->avctx = avctx;
dsputil_init(&s->dsp, avctx); dsputil_init(&s->dsp, avctx);
ff_init_scantable(s->dsp.idct_permutation, &s->scantable, ff_zigzag_direct); ff_init_scantable(s->dsp.idct_permutation, &s->scantable, ff_zigzag_direct);
...@@ -282,8 +286,8 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) ...@@ -282,8 +286,8 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
s->height < ((s->org_height * 3) / 4)) { s->height < ((s->org_height * 3) / 4)) {
s->interlaced = 1; s->interlaced = 1;
s->bottom_field = s->interlace_polarity; s->bottom_field = s->interlace_polarity;
s->picture.interlaced_frame = 1; s->picture_ptr->interlaced_frame = 1;
s->picture.top_field_first = !s->interlace_polarity; s->picture_ptr->top_field_first = !s->interlace_polarity;
height *= 2; height *= 2;
} }
...@@ -342,20 +346,19 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) ...@@ -342,20 +346,19 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
s->avctx->pix_fmt = PIX_FMT_GRAY16; s->avctx->pix_fmt = PIX_FMT_GRAY16;
} }
if(s->picture.data[0]) if(s->picture_ptr->data[0])
s->avctx->release_buffer(s->avctx, &s->picture); s->avctx->release_buffer(s->avctx, s->picture_ptr);
s->picture.reference= 0; if(s->avctx->get_buffer(s->avctx, s->picture_ptr) < 0){
if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1; return -1;
} }
s->picture.pict_type= FF_I_TYPE; s->picture_ptr->pict_type= FF_I_TYPE;
s->picture.key_frame= 1; s->picture_ptr->key_frame= 1;
s->got_picture = 1; s->got_picture = 1;
for(i=0; i<3; i++){ for(i=0; i<3; i++){
s->linesize[i]= s->picture.linesize[i] << s->interlaced; s->linesize[i]= s->picture_ptr->linesize[i] << s->interlaced;
} }
// printf("%d %d %d %d %d %d\n", s->width, s->height, s->linesize[0], s->linesize[1], s->interlaced, s->avctx->height); // printf("%d %d %d %d %d %d\n", s->width, s->height, s->linesize[0], s->linesize[1], s->interlaced, s->avctx->height);
...@@ -804,7 +807,7 @@ static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, i ...@@ -804,7 +807,7 @@ static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, i
} }
for(i=0; i < nb_components; i++) { for(i=0; i < nb_components; i++) {
int c = s->comp_index[i]; int c = s->comp_index[i];
data[c] = s->picture.data[c]; data[c] = s->picture_ptr->data[c];
reference_data[c] = reference ? reference->data[c] : NULL; reference_data[c] = reference ? reference->data[c] : NULL;
linesize[c]=s->linesize[c]; linesize[c]=s->linesize[c];
s->coefs_finished[c] |= 1; s->coefs_finished[c] |= 1;
...@@ -1017,6 +1020,7 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s, ...@@ -1017,6 +1020,7 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s,
skip_bits(&s->gb, 8); skip_bits(&s->gb, 8);
if(s->lossless){ if(s->lossless){
av_assert0(s->picture_ptr == &s->picture);
if(CONFIG_JPEGLS_DECODER && s->ls){ if(CONFIG_JPEGLS_DECODER && s->ls){
// for(){ // for(){
// reset_ls_coding_parameters(s, 0); // reset_ls_coding_parameters(s, 0);
...@@ -1034,6 +1038,7 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s, ...@@ -1034,6 +1038,7 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s,
} }
}else{ }else{
if(s->progressive && predictor) { if(s->progressive && predictor) {
av_assert0(s->picture_ptr == &s->picture);
if(mjpeg_decode_scan_progressive_ac(s, predictor, ilv, prev_shift, point_transform) < 0) if(mjpeg_decode_scan_progressive_ac(s, predictor, ilv, prev_shift, point_transform) < 0)
return -1; return -1;
} else { } else {
...@@ -1504,7 +1509,7 @@ eoi_parser: ...@@ -1504,7 +1509,7 @@ eoi_parser:
if (s->bottom_field == !s->interlace_polarity) if (s->bottom_field == !s->interlace_polarity)
goto not_the_end; goto not_the_end;
} }
*picture = s->picture; *picture = *s->picture_ptr;
*data_size = sizeof(AVFrame); *data_size = sizeof(AVFrame);
if(!s->lossless){ if(!s->lossless){
...@@ -1576,8 +1581,8 @@ av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx) ...@@ -1576,8 +1581,8 @@ av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx)
MJpegDecodeContext *s = avctx->priv_data; MJpegDecodeContext *s = avctx->priv_data;
int i, j; int i, j;
if (s->picture.data[0]) if (s->picture_ptr && s->picture_ptr->data[0])
avctx->release_buffer(avctx, &s->picture); avctx->release_buffer(avctx, s->picture_ptr);
av_free(s->buffer); av_free(s->buffer);
av_free(s->qscale_table); av_free(s->qscale_table);
......
...@@ -81,6 +81,7 @@ typedef struct MJpegDecodeContext { ...@@ -81,6 +81,7 @@ typedef struct MJpegDecodeContext {
int quant_index[4]; /* quant table index for each component */ int quant_index[4]; /* quant table index for each component */
int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */ int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */
AVFrame picture; /* picture structure */ AVFrame picture; /* picture structure */
AVFrame *picture_ptr; /* pointer to picture structure */
int got_picture; ///< we found a SOF and picture is valid, too. int got_picture; ///< we found a SOF and picture is valid, too.
int linesize[MAX_COMPONENTS]; ///< linesize << interlaced int linesize[MAX_COMPONENTS]; ///< linesize << interlaced
int8_t *qscale_table; int8_t *qscale_table;
......
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