1 @TEMPLATE decoder_tmpl.c 2 Decode With Drops Example 3 ========================= 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INTRODUCTION 5 This is an example utility which drops a series of frames, as specified 6 on the command line. This is useful for observing the error recovery 7 features of the codec. 8 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INTRODUCTION 9 10 Usage 11 ----- 12 This example adds a single argument to the `simple_decoder` example, 13 which specifies the range or pattern of frames to drop. The parameter is 14 parsed as follows: 15 16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ USAGE 17 if(argc!=4) 18 die("Usage: %s <infile> <outfile> <N-M|N/M>\n", argv[0]); 19 { 20 char *nptr; 21 n = strtol(argv[3], &nptr, 0); 22 m = strtol(nptr+1, NULL, 0); 23 is_range = *nptr == '-'; 24 if(!n || !m || (*nptr != '-' && *nptr != '/')) 25 die("Couldn't parse pattern %s\n", argv[3]); 26 } 27 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ USAGE 28 29 30 Dropping A Range Of Frames 31 -------------------------- 32 To drop a range of frames, specify the starting frame and the ending 33 frame to drop, separated by a dash. The following command will drop 34 frames 5 through 10 (base 1). 35 36 $ ./decode_with_drops in.ivf out.i420 5-10 37 38 39 Dropping A Pattern Of Frames 40 ---------------------------- 41 To drop a pattern of frames, specify the number of frames to drop and 42 the number of frames after which to repeat the pattern, separated by 43 a forward-slash. The following command will drop 3 of 7 frames. 44 Specifically, it will decode 4 frames, then drop 3 frames, and then 45 repeat. 46 47 $ ./decode_with_drops in.ivf out.i420 3/7 48 49 50 Extra Variables 51 --------------- 52 This example maintains the pattern passed on the command line in the 53 `n`, `m`, and `is_range` variables: 54 55 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EXTRA_VARS 56 int n, m, is_range; 57 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EXTRA_VARS 58 59 60 Making The Drop Decision 61 ------------------------ 62 The example decides whether to drop the frame based on the current 63 frame number, immediately before decoding the frame. 64 65 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PRE_DECODE 66 if((is_range && frame_cnt >= n && frame_cnt <= m) 67 ||(!is_range && m - (frame_cnt-1)%m <= n)) { 68 putc('X', stdout); 69 continue; 70 } 71 putc('.', stdout); 72 fflush(stdout); 73 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PRE_DECODE 74