Revision a8824a79 vhook/null.c

View differences:

vhook/null.c
34 34
    // ... and later converts back frame from RGB to initial format
35 35
    struct SwsContext *fromRGB_convert_ctx;
36 36

  
37
    enum PixelFormat sws_pix_fmt;   // Sws_Context is opaque, we need to save
38
    int sws_width, sws_height;      // this to check if we can re-use contexts
39
    // Contexts will be re-used 99% of time,
40
    // I know of width/height changes only in DVB broadcasts
41

  
42 37
} ContextInfo;
43 38

  
44 39
void Release(void *ctx)
......
79 74
        avpicture_fill(&picture1, buf, PIX_FMT_RGB24, width, height);
80 75

  
81 76
        // if we already got a SWS context, let's realloc if is not re-useable
82
        if (ci->toRGB_convert_ctx != NULL) {
83
            if ((ci->sws_pix_fmt != pix_fmt) ||
84
                 (ci->sws_width != width) || (ci->sws_height != height)) {
85
                sws_freeContext(ci->toRGB_convert_ctx);
86
                ci->toRGB_convert_ctx = NULL;
87
                sws_freeContext(ci->fromRGB_convert_ctx);
88
                ci->fromRGB_convert_ctx = NULL;
89
            }
90
        }
77
        ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
78
                                    width, height, pix_fmt,
79
                                    width, height, PIX_FMT_RGB24,
80
                                    sws_flags, NULL, NULL, NULL);
91 81
        if (ci->toRGB_convert_ctx == NULL) {
92
            ci->sws_pix_fmt = pix_fmt;
93
            ci->sws_width = width;
94
            ci->sws_height = height;
95
            ci->toRGB_convert_ctx = sws_getContext(
96
                                             ci->sws_width, ci->sws_height,
97
                                             ci->sws_pix_fmt,
98
                                             ci->sws_width, ci->sws_height,
99
                                             PIX_FMT_RGB24,
100
                                             sws_flags, NULL, NULL, NULL);
101
            if (ci->toRGB_convert_ctx == NULL) {
102
                av_log(NULL, AV_LOG_ERROR,
103
                       "Cannot initialize the toRGB conversion context\n");
104
                exit(1);
105
            }
106
            ci->fromRGB_convert_ctx = sws_getContext(
107
                                             ci->sws_width, ci->sws_height,
108
                                             PIX_FMT_RGB24,
109
                                             ci->sws_width, ci->sws_height,
110
                                             ci->sws_pix_fmt,
111
                                             sws_flags, NULL, NULL, NULL);
112
            if (ci->fromRGB_convert_ctx == NULL) {
113
                av_log(NULL, AV_LOG_ERROR,
114
                       "Cannot initialize the fromRGB conversion context\n");
115
                exit(1);
116
            }
82
            av_log(NULL, AV_LOG_ERROR,
83
                   "Cannot initialize the toRGB conversion context\n");
84
            exit(1);
117 85
        }
118 86
// img_convert parameters are          2 first destination, then 4 source
119 87
// sws_scale   parameters are context, 4 first source,      then 2 destination
120 88
        sws_scale(ci->toRGB_convert_ctx,
121
            picture->data, picture->linesize, 0, ci->sws_height,
89
            picture->data, picture->linesize, 0, height,
122 90
            picture1.data, picture1.linesize);
123 91

  
124 92
        pict = &picture1;
......
127 95
    /* Insert filter code here */
128 96

  
129 97
    if (pix_fmt != PIX_FMT_RGB24) {
98
        ci->fromRGB_convert_ctx = sws_getCachedContext(ci->fromRGB_convert_ctx,
99
                                        width, height, PIX_FMT_RGB24,
100
                                        width, height, pix_fmt,
101
                                        sws_flags, NULL, NULL, NULL);
102
        if (ci->fromRGB_convert_ctx == NULL) {
103
            av_log(NULL, AV_LOG_ERROR,
104
                   "Cannot initialize the fromRGB conversion context\n");
105
            exit(1);
106
        }
107
// img_convert parameters are          2 first destination, then 4 source
108
// sws_scale   parameters are context, 4 first source,      then 2 destination
130 109
        sws_scale(ci->fromRGB_convert_ctx,
131
            picture1.data, picture1.linesize, 0, ci->sws_height,
110
            picture1.data, picture1.linesize, 0, height,
132 111
            picture->data, picture->linesize);
133 112
    }
134 113

  

Also available in: Unified diff