xpra icon
Bug tracker and wiki

Ticket #281: x264-ifdef-encoder-win32-v3.patch

File x264-ifdef-encoder-win32-v3.patch, 5.5 KB (added by Antoine Martin, 7 years ago)

cleanup, remove ifdefs and allow x264 encoding on win32

  • xpra/x264/codec.pyx

     
    3333    ctypedef void** const_void_pp "const void**"
    3434    int PyObject_AsReadBuffer(object obj, void ** buffer, Py_ssize_t * buffer_len) except -1
    3535
     36#needed for win32?
     37cdef extern from "stdint.h":
     38    pass
     39cdef extern from "inttypes.h":
     40    pass
     41
    3642ctypedef unsigned char uint8_t
    3743ctypedef void x264lib_ctx
    3844ctypedef void x264_picture_t
  • xpra/x264/x264lib.c

     
    1111#include <sys/types.h>
    1212#include <sys/stat.h>
    1313#include <fcntl.h>
    14 #include <math.h>
     14#include <malloc.h>
     15#include <stdint.h>
     16#include <inttypes.h>
    1517
     18#include "x264lib.h"
     19#include <x264.h>
     20#include <libswscale/swscale.h>
     21#include <libavcodec/avcodec.h>
     22#include <libavutil/mem.h>
     23
     24
    1625//not honoured on MS Windows:
    1726#define MEMALIGN 1
    1827//not honoured on OSX:
     
    2130//(ie: when not supported by the library we build against)
    2231#define SUPPORT_CSC_MODES 1
    2332
    24 #ifdef _WIN32
    25 #include <malloc.h>
    26 #include "stdint.h"
    27 #include "inttypes.h"
    28 #else
    29 #include <stdint.h>
    30 #include <unistd.h>
    31 #endif
    3233
    33 #ifdef _WIN32
    34 typedef void x264_t;
    35 #define inline __inline
    36 #else
    37 #include <x264.h>
    38 #endif
    39 
    40 #include <libswscale/swscale.h>
    41 #include <libavcodec/avcodec.h>
    42 #include <libavutil/mem.h>
    43 #include "x264lib.h"
    44 
    4534//beware that these macros may evaluate a or b twice!
    4635//ie: do not use them for something like: MAX(i++, N)
    4736#define MAX(a,b) ((a) > (b) ? a : b)
     
    10897        return ctx->speed;
    10998}
    11099
    111 #ifndef _WIN32
    112100//Given a quality percentage (0 to 100),
    113101//return the x264 quality constant to use
    114102float get_x264_quality(int pct) {
    115         return  roundf(50.0 - (MIN(100, MAX(0, pct)) * 49.0 / 100.0));
     103        return  50.0f - (MIN(100, MAX(0, pct)) * 49.0f / 100.0f);
    116104}
    117105
    118106//Given a quality percentage (0 to 100),
     
    169157                return -1;
    170158        }
    171159}
    172 #endif
    173160
    174161//Given a csc colour sampling constant,
    175162//return our own generic csc constant (see codec_constants.py)
     
    211198const int DEFAULT_I422_MIN_QUALITY = 80;
    212199const int DEFAULT_I444_MIN_QUALITY = 90;
    213200
    214 #ifndef _WIN32
    215201//Given a quality percentage (0 to 100)
    216202//return the profile to use
    217203//IMPORTANT: changes here must be reflected in get_x264_colour_sampling
     
    232218const char *get_valid_profile(const char* csc_mode, const char *profile, const char *profiles[], const char *default_profile)
    233219{
    234220        //printf("get_valid_profile(%s, %s, %p, %s)\n", csc_mode, profile, profiles, default_profile);
     221        int i = 0;
    235222        if (profile==NULL)
    236223                return  default_profile;
    237         int i = 0;
    238224        while (profiles[i]!=NULL)
    239225        {
    240226                if (strcmp(profiles[i], profile)==0) {
     
    375361        }
    376362}
    377363
    378 #else
    379 struct x264lib_ctx *init_encoder(int width, int height,
    380                 int initial_quality, int initial_speed,
    381                 int supports_csc_option,
    382                 int I422_quality, int I444_quality,
    383                 int I422_min, int I444_min,
    384         char *i420_profile, char *i422_profile, char *i444_profile)
    385 {
    386         return NULL;
    387 }
    388364
    389 void clean_encoder(struct x264lib_ctx *ctx)
    390 {
    391         return;
    392 }
    393 #endif
    394 
    395365int init_decoder_context(struct x264lib_ctx *ctx, int width, int height, int csc_fmt)
    396366{
    397367        if (csc_fmt<0)
     
    459429        free(ctx);
    460430}
    461431
    462 #ifndef _WIN32
     432
    463433x264_picture_t *csc_image_rgb2yuv(struct x264lib_ctx *ctx, const uint8_t *in, int stride)
    464434{
    465435        if (!ctx->encoder || !ctx->rgb2yuv)
     
    507477        *outsz = frame_size;
    508478        return 0;
    509479}
    510 #else
    511 x264_picture_t* csc_image_rgb2yuv(struct x264lib_ctx *ctx, const uint8_t *in, int stride)
    512 {
    513         return  NULL;
    514 }
    515 int compress_image(struct x264lib_ctx *ctx, x264_picture_t *pic_in, uint8_t **out, int *outsz)
    516 {
    517         return 1;
    518 }
    519 #endif
    520480
     481
    521482int csc_image_yuv2rgb(struct x264lib_ctx *ctx, uint8_t *in[3], const int stride[3], uint8_t **out, int *outsz, int *outstride)
    522483{
    523484        AVPicture pic;
     
    594555 * Change the speed of encoding (x264 preset).
    595556 * @param percent: 100 for maximum ("ultrafast") with lowest compression, 0 for highest compression (slower)
    596557 */
    597 #ifndef _WIN32
    598558void set_encoding_speed(struct x264lib_ctx *ctx, int pct)
    599559{
    600560        x264_param_t param;
     
    614574        x264_param_apply_profile(&param, ctx->profile);
    615575        x264_encoder_reconfig(ctx->encoder, &param);
    616576}
    617 #else
    618 void set_encoding_speed(struct x264lib_ctx *ctx, int pct)
    619 {
    620         ;
    621 }
    622 #endif
    623577
    624578/**
    625579 * Change the quality of encoding (x264 f_rf_constant).
    626580 * @param percent: 100 for best quality, 0 for lowest quality.
    627581 */
    628 #ifndef _WIN32
    629582void set_encoding_quality(struct x264lib_ctx *ctx, int pct)
    630583{
    631584        float new_quality = get_x264_quality(pct);
     
    664617                ctx->rgb2yuv = init_encoder_csc(ctx);
    665618        }
    666619}
    667 #else
    668 void set_encoding_quality(struct x264lib_ctx *ctx, int pct)
    669 {
    670         ;
    671 }
    672 #endif
    673620
    674621
    675622void* xmemalign(size_t size)
  • xpra/x264/x264lib.h

     
    55 * later version. See the file COPYING for details.
    66 */
    77
    8 #ifdef _WIN32
    9 #include "stdint.h"
    10 #include "inttypes.h"
    11 #else
    12 #include "stdint.h"
    13 #include "stdlib.h"
    14 #endif
    15 
    16 #ifndef _WIN32
     8#include <stdint.h>
     9#include <inttypes.h>
    1710#include <x264.h>
    18 #else
    19 #define inline __inline
    20 typedef void * x264_picture_t;
    21 #endif
    2211
    2312/** Opaque structure - "context". You must have a context to encode images of a given size */
    2413struct x264lib_ctx;