Browse code

avfilter/vf_stereo3d: get rid of ts_unit hack

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2015/12/16 20:36:21
Showing 1 changed files
... ...
@@ -148,7 +148,6 @@ typedef struct Stereo3DContext {
148 148
     int hsub, vsub;
149 149
     int pixstep[4];
150 150
     AVFrame *prev;
151
-    double ts_unit;
152 151
     int blanks;
153 152
     int in_off_left[4], in_off_right[4];
154 153
     Stereo3DDSPContext dsp;
... ...
@@ -544,7 +543,6 @@ static int config_output(AVFilterLink *outlink)
544 544
         return ret;
545 545
     s->nb_planes = av_pix_fmt_count_planes(outlink->format);
546 546
     av_image_fill_max_pixsteps(s->pixstep, NULL, desc);
547
-    s->ts_unit = av_q2d(av_inv_q(av_mul_q(outlink->frame_rate, outlink->time_base)));
548 547
     s->pheight[1] = s->pheight[2] = FF_CEIL_RSHIFT(s->height, desc->log2_chroma_h);
549 548
     s->pheight[0] = s->pheight[3] = s->height;
550 549
     s->hsub = desc->log2_chroma_w;
... ...
@@ -593,11 +591,21 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
593 593
     AVFilterLink *outlink = ctx->outputs[0];
594 594
     AVFrame *out, *oleft, *oright, *ileft, *iright;
595 595
     int out_off_left[4], out_off_right[4];
596
-    int i;
596
+    int i, ret;
597 597
 
598 598
     if (s->in.format == s->out.format)
599 599
         return ff_filter_frame(outlink, inpicref);
600 600
 
601
+    switch (s->out.format) {
602
+    case ALTERNATING_LR:
603
+    case ALTERNATING_RL:
604
+        if (!s->prev) {
605
+            s->prev = inpicref;
606
+            return 0;
607
+        }
608
+        break;
609
+    };
610
+
601 611
     switch (s->in.format) {
602 612
     case ALTERNATING_LR:
603 613
     case ALTERNATING_RL:
... ...
@@ -624,8 +632,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
624 624
          s->in.format == ABOVE_BELOW_RL ||
625 625
          s->in.format == ABOVE_BELOW_2_LR ||
626 626
          s->in.format == ABOVE_BELOW_2_RL)) {
627
-        oright = av_frame_clone(inpicref);
628
-        oleft  = av_frame_clone(inpicref);
627
+        oright = av_frame_clone(s->prev);
628
+        oleft  = av_frame_clone(s->prev);
629 629
         if (!oright || !oleft) {
630 630
             av_frame_free(&oright);
631 631
             av_frame_free(&oleft);
... ...
@@ -649,6 +657,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
649 649
             av_frame_free(&inpicref);
650 650
             return AVERROR(ENOMEM);
651 651
         }
652
+    } else if ((s->out.format == MONO_L && s->in.format == ALTERNATING_LR) ||
653
+               (s->out.format == MONO_R && s->in.format == ALTERNATING_RL)) {
654
+        s->prev->pts /= 2;
655
+        ret = ff_filter_frame(outlink, s->prev);
656
+        av_frame_free(&inpicref);
657
+        s->prev = NULL;
658
+        return ret;
659
+    } else if ((s->out.format == MONO_L && s->in.format == ALTERNATING_RL) ||
660
+               (s->out.format == MONO_R && s->in.format == ALTERNATING_LR)) {
661
+        av_frame_free(&s->prev);
662
+        inpicref->pts /= 2;
663
+        return ff_filter_frame(outlink, inpicref);
664
+    } else if ((s->out.format == ALTERNATING_LR && s->in.format == ALTERNATING_RL) ||
665
+               (s->out.format == ALTERNATING_RL && s->in.format == ALTERNATING_LR)) {
666
+        FFSWAP(int64_t, s->prev->pts, inpicref->pts);
667
+        ff_filter_frame(outlink, inpicref);
668
+        ret = ff_filter_frame(outlink, s->prev);
669
+        s->prev = NULL;
670
+        return ret;
652 671
     } else {
653 672
         out = oleft = oright = ff_get_video_buffer(outlink, outlink->w, outlink->h);
654 673
         if (!out) {
... ...
@@ -667,7 +694,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
667 667
                 av_frame_free(&inpicref);
668 668
                 return AVERROR(ENOMEM);
669 669
             }
670
-            av_frame_copy_props(oright, inpicref);
670
+            av_frame_copy_props(oright, s->prev);
671 671
         }
672 672
     }
673 673
 
... ...
@@ -902,18 +929,23 @@ copy:
902 902
         av_assert0(0);
903 903
     }
904 904
 
905
-    av_frame_free(&inpicref);
906
-    av_frame_free(&s->prev);
907 905
     if (oright != oleft) {
908 906
         if (s->out.format == ALTERNATING_LR)
909 907
             FFSWAP(AVFrame *, oleft, oright);
910
-        oright->pts = outlink->frame_count * s->ts_unit;
908
+        oright->pts = s->prev->pts * 2;
911 909
         ff_filter_frame(outlink, oright);
912 910
         out = oleft;
913
-        oleft->pts = outlink->frame_count * s->ts_unit;
911
+        oleft->pts = s->prev->pts + inpicref->pts;
912
+        av_frame_free(&s->prev);
913
+        s->prev = inpicref;
914 914
     } else if (s->in.format == ALTERNATING_LR ||
915 915
                s->in.format == ALTERNATING_RL) {
916
-        out->pts = outlink->frame_count * s->ts_unit;
916
+        out->pts = s->prev->pts / 2;
917
+        av_frame_free(&s->prev);
918
+        av_frame_free(&inpicref);
919
+    } else {
920
+        av_frame_free(&s->prev);
921
+        av_frame_free(&inpicref);
917 922
     }
918 923
     return ff_filter_frame(outlink, out);
919 924
 }