You've already forked FFmpeg
							
							
				mirror of
				https://github.com/FFmpeg/FFmpeg.git
				synced 2025-10-30 23:18:11 +02:00 
			
		
		
		
	lavc/ffv1enc: move bit writer to per-slice context
This commit is contained in:
		| @@ -79,13 +79,14 @@ typedef struct FFV1SliceContext { | ||||
|     int slice_y; | ||||
|  | ||||
|     int run_index; | ||||
|  | ||||
|     PutBitContext pb; | ||||
| } FFV1SliceContext; | ||||
|  | ||||
| typedef struct FFV1Context { | ||||
|     AVClass *class; | ||||
|     AVCodecContext *avctx; | ||||
|     RangeCoder c; | ||||
|     PutBitContext pb; | ||||
|     uint64_t rc_stat[256][2]; | ||||
|     uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2]; | ||||
|     int version; | ||||
|   | ||||
| @@ -1057,7 +1057,7 @@ retry: | ||||
|     } | ||||
|     if (fs->ac == AC_GOLOMB_RICE) { | ||||
|         fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&fs->c, f->version > 2) : 0; | ||||
|         init_put_bits(&fs->pb, | ||||
|         init_put_bits(&sc->pb, | ||||
|                       fs->c.bytestream_start + fs->ac_byte_count, | ||||
|                       fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count); | ||||
|     } | ||||
| @@ -1209,13 +1209,14 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, | ||||
|     buf_p = pkt->data; | ||||
|     for (i = 0; i < f->slice_count; i++) { | ||||
|         FFV1Context *fs = f->slice_context[i]; | ||||
|         FFV1SliceContext *sc = &f->slices[i]; | ||||
|         int bytes; | ||||
|  | ||||
|         if (fs->ac != AC_GOLOMB_RICE) { | ||||
|             bytes = ff_rac_terminate(&fs->c, 1); | ||||
|         } else { | ||||
|             flush_put_bits(&fs->pb); // FIXME: nicer padding | ||||
|             bytes = fs->ac_byte_count + put_bytes_output(&fs->pb); | ||||
|             flush_put_bits(&sc->pb); // FIXME: nicer padding | ||||
|             bytes = fs->ac_byte_count + put_bytes_output(&sc->pb); | ||||
|         } | ||||
|         if (i > 0 || f->version > 2) { | ||||
|             av_assert0(bytes < pkt->size / f->slice_count); | ||||
|   | ||||
| @@ -39,7 +39,7 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, | ||||
|             return AVERROR_INVALIDDATA; | ||||
|         } | ||||
|     } else { | ||||
|         if (put_bytes_left(&s->pb, 0) < w * 4) { | ||||
|         if (put_bytes_left(&sc->pb, 0) < w * 4) { | ||||
|             av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); | ||||
|             return AVERROR_INVALIDDATA; | ||||
|         } | ||||
| @@ -86,10 +86,10 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, | ||||
|                     while (run_count >= 1 << ff_log2_run[run_index]) { | ||||
|                         run_count -= 1 << ff_log2_run[run_index]; | ||||
|                         run_index++; | ||||
|                         put_bits(&s->pb, 1, 1); | ||||
|                         put_bits(&sc->pb, 1, 1); | ||||
|                     } | ||||
|  | ||||
|                     put_bits(&s->pb, 1 + ff_log2_run[run_index], run_count); | ||||
|                     put_bits(&sc->pb, 1 + ff_log2_run[run_index], run_count); | ||||
|                     if (run_index) | ||||
|                         run_index--; | ||||
|                     run_count = 0; | ||||
| @@ -103,21 +103,21 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, | ||||
|  | ||||
|             ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n", | ||||
|                     run_count, run_index, run_mode, x, | ||||
|                     (int)put_bits_count(&s->pb)); | ||||
|                     (int)put_bits_count(&sc->pb)); | ||||
|  | ||||
|             if (run_mode == 0) | ||||
|                 put_vlc_symbol(&s->pb, &p->vlc_state[context], diff, bits); | ||||
|                 put_vlc_symbol(&sc->pb, &p->vlc_state[context], diff, bits); | ||||
|         } | ||||
|     } | ||||
|     if (run_mode) { | ||||
|         while (run_count >= 1 << ff_log2_run[run_index]) { | ||||
|             run_count -= 1 << ff_log2_run[run_index]; | ||||
|             run_index++; | ||||
|             put_bits(&s->pb, 1, 1); | ||||
|             put_bits(&sc->pb, 1, 1); | ||||
|         } | ||||
|  | ||||
|         if (run_count) | ||||
|             put_bits(&s->pb, 1, 1); | ||||
|             put_bits(&sc->pb, 1, 1); | ||||
|     } | ||||
|     sc->run_index = run_index; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user