| 212 | } |
| 213 | |
| 214 | static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg, |
| 215 | AVStream *st, AVPacket *pkt, uint32_t *timestamp, |
| 216 | const uint8_t *buf, int len, uint16_t seq, |
| 217 | int flags) |
| 218 | { |
| 219 | uint8_t type, q, width, height; |
| 220 | const uint8_t *qtables = NULL; |
| 221 | uint16_t qtable_len; |
| 222 | uint32_t off; |
| 223 | int ret, dri = 0; |
| 224 | |
| 225 | if (len < 8) { |
| 226 | av_log(ctx, AV_LOG_ERROR, "Too short RTP/JPEG packet.\n"); |
| 227 | return AVERROR_INVALIDDATA; |
| 228 | } |
| 229 | |
| 230 | /* Parse the main JPEG header. */ |
| 231 | off = AV_RB24(buf + 1); /* fragment byte offset */ |
| 232 | type = AV_RB8(buf + 4); /* id of jpeg decoder params */ |
| 233 | q = AV_RB8(buf + 5); /* quantization factor (or table id) */ |
| 234 | width = AV_RB8(buf + 6); /* frame width in 8 pixel blocks */ |
| 235 | height = AV_RB8(buf + 7); /* frame height in 8 pixel blocks */ |
| 236 | st->codecpar->width = width*8; |
| 237 | st->codecpar->height = height*8; |
| 238 | buf += 8; |
| 239 | len -= 8; |
| 240 | |
| 241 | if (type & 0x40) { |
| 242 | if (len < 4) { |
| 243 | av_log(ctx, AV_LOG_ERROR, "Too short RTP/JPEG packet.\n"); |
| 244 | return AVERROR_INVALIDDATA; |
| 245 | } |
| 246 | dri = AV_RB16(buf); |
| 247 | buf += 4; |
| 248 | len -= 4; |
| 249 | type &= ~0x40; |
| 250 | } |
| 251 | if (type > 1) { |
| 252 | avpriv_report_missing_feature(ctx, "RTP/JPEG type %"PRIu8, type); |
| 253 | return AVERROR_PATCHWELCOME; |
| 254 | } |
| 255 | |
| 256 | /* Parse the quantization table header. */ |
| 257 | if (off == 0) { |
| 258 | /* Start of JPEG data packet. */ |
| 259 | uint8_t new_qtables[128]; |
| 260 | uint8_t hdr[1024]; |
| 261 | |
| 262 | if (q > 127) { |
| 263 | uint8_t precision; |
| 264 | if (len < 4) { |
| 265 | av_log(ctx, AV_LOG_ERROR, "Too short RTP/JPEG packet.\n"); |
| 266 | return AVERROR_INVALIDDATA; |
| 267 | } |
| 268 | |
| 269 | /* The first byte is reserved for future use. */ |
| 270 | precision = AV_RB8(buf + 1); /* size of coefficients */ |
| 271 | qtable_len = AV_RB16(buf + 2); /* length in bytes */ |
nothing calls this directly
no test coverage detected