comparison mjpeg.c @ 4977:9d7c1fbd3359 libavcodec

move mjpeg parser in its own file
author aurel
date Thu, 10 May 2007 22:37:36 +0000
parents 0d1cc37d9430
children 3fa689636240
comparison
equal deleted inserted replaced
4976:bde9b89ed72c 4977:9d7c1fbd3359
959 } 959 }
960 960
961 return 0; 961 return 0;
962 } 962 }
963 963
964
965 /**
966 * finds the end of the current frame in the bitstream.
967 * @return the position of the first byte of the next frame, or -1
968 */
969 static int find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
970 int vop_found, i;
971 uint16_t state;
972
973 vop_found= pc->frame_start_found;
974 state= pc->state;
975
976 i=0;
977 if(!vop_found){
978 for(i=0; i<buf_size; i++){
979 state= (state<<8) | buf[i];
980 if(state == 0xFFD8){
981 i++;
982 vop_found=1;
983 break;
984 }
985 }
986 }
987
988 if(vop_found){
989 /* EOF considered as end of frame */
990 if (buf_size == 0)
991 return 0;
992 for(; i<buf_size; i++){
993 state= (state<<8) | buf[i];
994 if(state == 0xFFD8){
995 pc->frame_start_found=0;
996 pc->state=0;
997 return i-1;
998 }
999 }
1000 }
1001 pc->frame_start_found= vop_found;
1002 pc->state= state;
1003 return END_NOT_FOUND;
1004 }
1005
1006 static int jpeg_parse(AVCodecParserContext *s,
1007 AVCodecContext *avctx,
1008 const uint8_t **poutbuf, int *poutbuf_size,
1009 const uint8_t *buf, int buf_size)
1010 {
1011 ParseContext *pc = s->priv_data;
1012 int next;
1013
1014 next= find_frame_end(pc, buf, buf_size);
1015
1016 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
1017 *poutbuf = NULL;
1018 *poutbuf_size = 0;
1019 return buf_size;
1020 }
1021
1022 *poutbuf = buf;
1023 *poutbuf_size = buf_size;
1024 return next;
1025 }
1026 964
1027 /* quantize tables */ 965 /* quantize tables */
1028 static int mjpeg_decode_dqt(MJpegDecodeContext *s) 966 static int mjpeg_decode_dqt(MJpegDecodeContext *s)
1029 { 967 {
1030 int len, index, i, j; 968 int len, index, i, j;
2624 encode_picture_lossless, 2562 encode_picture_lossless,
2625 MPV_encode_end, 2563 MPV_encode_end,
2626 }; 2564 };
2627 #endif 2565 #endif
2628 2566
2629 #ifdef CONFIG_MJPEG_PARSER
2630 AVCodecParser mjpeg_parser = {
2631 { CODEC_ID_MJPEG },
2632 sizeof(ParseContext),
2633 NULL,
2634 jpeg_parse,
2635 ff_parse_close,
2636 };
2637 #endif
2638
2639 AVBitStreamFilter mjpega_dump_header_bsf = { 2567 AVBitStreamFilter mjpega_dump_header_bsf = {
2640 "mjpegadump", 2568 "mjpegadump",
2641 0, 2569 0,
2642 mjpega_dump_header, 2570 mjpega_dump_header,
2643 }; 2571 };