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