OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2007-2008 Intel Corporation. All Rights Reserved. |
| 3 * |
| 4 * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 * copy of this software and associated documentation files (the |
| 6 * "Software"), to deal in the Software without restriction, including |
| 7 * without limitation the rights to use, copy, modify, merge, publish, |
| 8 * distribute, sub license, and/or sell copies of the Software, and to |
| 9 * permit persons to whom the Software is furnished to do so, subject to |
| 10 * the following conditions: |
| 11 * |
| 12 * The above copyright notice and this permission notice (including the |
| 13 * next paragraph) shall be included in all copies or substantial portions |
| 14 * of the Software. |
| 15 * |
| 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
| 19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR |
| 20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 */ |
| 24 |
| 25 /* |
| 26 * it is a real program to show how VAAPI encoding work, |
| 27 * It does H264 element stream level encoding on auto-generated YUV data |
| 28 * |
| 29 * gcc -o h264encode h264encode -lva -lva-x11 |
| 30 * ./h264encode -w <width> -h <height> -n <frame_num> |
| 31 * |
| 32 */ |
| 33 #include <stdio.h> |
| 34 #include <string.h> |
| 35 #include <stdlib.h> |
| 36 #include <getopt.h> |
| 37 #include <unistd.h> |
| 38 #include <sys/types.h> |
| 39 #include <sys/stat.h> |
| 40 #include <fcntl.h> |
| 41 #include <assert.h> |
| 42 #include <va/va.h> |
| 43 #include <X11/Xlib.h> |
| 44 #include <va/va_x11.h> |
| 45 |
| 46 #define SURFACE_NUM 18 /* 16 surfaces for src, 2 surface for reconstructed/refer
ence */ |
| 47 |
| 48 static Display *x11_display; |
| 49 static VADisplay va_dpy; |
| 50 static VASurfaceID surface_id[SURFACE_NUM]; |
| 51 static Window display_win = 0; |
| 52 static int win_width; |
| 53 static int win_height; |
| 54 static int frame_width=352, frame_height=288; |
| 55 |
| 56 static int display_surface(int frame_id, int *exit_encode) |
| 57 { |
| 58 Window win = display_win; |
| 59 XEvent event; |
| 60 VAStatus va_status; |
| 61 |
| 62 if (win == 0) { /* display reconstructed surface */ |
| 63 win_width = frame_width; |
| 64 win_height = frame_height; |
| 65 |
| 66 win = XCreateSimpleWindow(x11_display, RootWindow(x11_display, 0), 0, 0, |
| 67 frame_width, frame_height, 0, 0, WhitePixel(x1
1_display, 0)); |
| 68 XMapWindow(x11_display, win); |
| 69 XSync(x11_display, False); |
| 70 |
| 71 display_win = win; |
| 72 } |
| 73 |
| 74 va_status = vaPutSurface(va_dpy, surface_id[frame_id], win, |
| 75 0,0, frame_width, frame_height, |
| 76 0,0, win_width, win_height, |
| 77 NULL,0,0); |
| 78 |
| 79 *exit_encode = 0; |
| 80 while(XPending(x11_display)) { |
| 81 XNextEvent(x11_display, &event); |
| 82 |
| 83 /* bail on any focused key press */ |
| 84 if(event.type == KeyPress) { |
| 85 *exit_encode = 1; |
| 86 break; |
| 87 } |
| 88 |
| 89 /* rescale the video to fit the window */ |
| 90 if(event.type == ConfigureNotify) { |
| 91 win_width = event.xconfigure.width; |
| 92 win_height = event.xconfigure.height; |
| 93 } |
| 94 } |
| 95 |
| 96 return 0; |
| 97 } |
| 98 |
| 99 #include "h264encode_common.c" |
OLD | NEW |