comparison mjpeg.c @ 2319:f9f257b41ec2 libavcodec

mjpeg parser
author michael
date Sun, 24 Oct 2004 22:37:29 +0000
parents 21f450be6cb5
children 816185a9594a
comparison
equal deleted inserted replaced
2318:1925d732ea42 2319:f9f257b41ec2
892 mjpeg_decode_dht(s); 892 mjpeg_decode_dht(s);
893 /* should check for error - but dunno */ 893 /* should check for error - but dunno */
894 } 894 }
895 895
896 return 0; 896 return 0;
897 }
898
899
900 /**
901 * finds the end of the current frame in the bitstream.
902 * @return the position of the first byte of the next frame, or -1
903 */
904 static int find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
905 int vop_found, i;
906 uint16_t state;
907
908 vop_found= pc->frame_start_found;
909 state= pc->state;
910
911 i=0;
912 if(!vop_found){
913 for(i=0; i<buf_size; i++){
914 state= (state<<8) | buf[i];
915 if(state == 0xFFD8){
916 i++;
917 vop_found=1;
918 break;
919 }
920 }
921 }
922
923 if(vop_found){
924 /* EOF considered as end of frame */
925 if (buf_size == 0)
926 return 0;
927 for(; i<buf_size; i++){
928 state= (state<<8) | buf[i];
929 if(state == 0xFFD8){
930 pc->frame_start_found=0;
931 pc->state=0;
932 return i-1;
933 }
934 }
935 }
936 pc->frame_start_found= vop_found;
937 pc->state= state;
938 return END_NOT_FOUND;
939 }
940
941 static int jpeg_parse(AVCodecParserContext *s,
942 AVCodecContext *avctx,
943 uint8_t **poutbuf, int *poutbuf_size,
944 const uint8_t *buf, int buf_size)
945 {
946 ParseContext *pc = s->priv_data;
947 int next;
948
949 next= find_frame_end(pc, buf, buf_size);
950
951 if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
952 *poutbuf = NULL;
953 *poutbuf_size = 0;
954 return buf_size;
955 }
956
957 *poutbuf = (uint8_t *)buf;
958 *poutbuf_size = buf_size;
959 return next;
897 } 960 }
898 961
899 /* quantize tables */ 962 /* quantize tables */
900 static int mjpeg_decode_dqt(MJpegDecodeContext *s) 963 static int mjpeg_decode_dqt(MJpegDecodeContext *s)
901 { 964 {
2222 MPV_encode_init, 2285 MPV_encode_init,
2223 encode_picture_lossless, 2286 encode_picture_lossless,
2224 MPV_encode_end, 2287 MPV_encode_end,
2225 }; 2288 };
2226 #endif 2289 #endif
2290
2291 AVCodecParser mjpeg_parser = {
2292 { CODEC_ID_MJPEG },
2293 sizeof(ParseContext),
2294 NULL,
2295 jpeg_parse,
2296 ff_parse_close,
2297 };
2298