1@TEMPLATE decoder_tmpl.c 2Postprocessing Decoder 3====================== 4~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INTRODUCTION 5This example adds postprocessing to the simple decoder loop. 6~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INTRODUCTION 7 8 9Initializing Postprocessing 10--------------------------- 11You must inform the codec that you might request postprocessing at 12initialization time. This is done by passing the VPX_CODEC_USE_POSTPROC 13flag to `vpx_codec_dec_init`. If the codec does not support 14postprocessing, this call will return VPX_CODEC_INCAPABLE. For 15demonstration purposes, we also fall back to default initialization if 16the codec does not provide support. 17~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DEC_INIT 18/* Initialize codec */ 19res = vpx_codec_dec_init(&codec, interface, NULL, 20 VPX_CODEC_USE_POSTPROC); 21if(res == VPX_CODEC_INCAPABLE) { 22 printf("NOTICE: Postproc not supported by %s\n", 23 vpx_codec_iface_name(interface)); 24 res = vpx_codec_dec_init(&codec, interface, NULL, 0); 25} 26if(res) 27 die_codec(&codec, "Failed to initialize decoder"); 28~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DEC_INIT 29 30 31Using Adaptive Postprocessing 32----------------------------- 33VP6 provides "adaptive postprocessing." It will automatically select the 34best postprocessing filter on a frame by frame basis based on the amount 35of time remaining before the user's specified deadline expires. The 36special value 0 indicates that the codec should take as long as 37necessary to provide the best quality frame. This example gives the 38codec 15ms (15000us) to return a frame. Remember that this is a soft 39deadline, and the codec may exceed it doing its regular processing. In 40these cases, no additional postprocessing will be done. 41~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DECODE 42/* Decode the frame with 15ms deadline */ 43if(vpx_codec_decode(&codec, frame, frame_sz, NULL, 15000)) 44 die_codec(&codec, "Failed to decode frame"); 45~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DECODE 46 47 48Codec Specific Postprocessing Controls 49-------------------------------------- 50Some codecs provide fine grained controls over their built-in 51postprocessors. VP8 is one example. The following sample code toggles 52postprocessing on and off every 15 frames. 53~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PRE_DECODE 54#if CONFIG_VP8_DECODER 55if(frame_cnt%30 == 1) { 56 vp8_postproc_cfg_t pp = {0, 0, 0}; 57 58 if(vpx_codec_control(&codec, VP8_SET_POSTPROC, &pp)) 59 die_codec(&codec, "Failed to turn off postproc"); 60} else if(frame_cnt%30 == 16) { 61 vp8_postproc_cfg_t pp = {VP8_DEBLOCK | VP8_DEMACROBLOCK, 4, 0}; 62 63 if(vpx_codec_control(&codec, VP8_SET_POSTPROC, &pp)) 64 die_codec(&codec, "Failed to turn on postproc"); 65}; 66#endif 67~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PRE_DECODE 68