Skip to content

Commit

Permalink
💥 Support native build
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Dec 27, 2024
1 parent 2ee0c89 commit 1fcfbef
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 38 deletions.
51 changes: 45 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,63 @@ permissions:

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- runs-on: ubuntu-latest
shell: bash
- runs-on: macos-latest
shell: bash
- runs-on: windows-latest
shell: msys2
runs-on: ${{matrix.runs-on}}
defaults:
run:
shell: ${{matrix.shell}} {0}
steps:
- uses: actions/checkout@v4
- name: Install dependencies
if: runner.os == 'Linux'
run: |
sudo add-apt-repository ppa:xmake-io/xmake
sudo apt-get -y update
sudo apt-get -y install xmake
sudo apt-get -y install meson
- name: Install dependencies
if: runner.os == 'macOS'
run: |
brew install meson
- uses: msys2/setup-msys2@v2
if: runner.os == 'Windows'
- name: Install dependencies
if: runner.os == 'Windows'
run: |
pacman -Sy --noconfirm mingw-w64-x86_64-meson
- name: Build
run: |
xmake
sed -i -e"s/, 'linearasm'//g" meson.build
meson setup build -Db_coverage=true
meson compile -Cbuild
meson test -Cbuild
mv build/x264 build/${{matrix.runs-on}}-x264 ||
mv build/x264.exe build/${{matrix.runs-on}}-x264.exe
- uses: actions/upload-artifact@v4
if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
with:
name: artifact-${{matrix.runs-on}}
path: |
x264
build/*-x264*
publish:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/download-artifact@v4
with:
pattern: artifact-*
merge-multiple: true
path: build
- uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
x264
build/*
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,79 @@ scripts/burn.js /the/path/of/352x288.yuv -- build/x264.out --input=352x288.yuv -
ffplay build/out.264
```

## Usage

See `--help`:

```sh
sed -i -e"s/, 'linearasm'//g" meson.build
meson setup build/host
meson compile -Cbuild/host
build/host/x264 --help
```

Here are some details:

### --disable-ddr-input/--disable-ddr-output

There are two methods to pass input/output file to/from TI DSP:

- CIO. for only debug, allow TI DSP read/write host machine filesystem, we can
get frame number from file size
- `loadRaw()/saveRaw()`. load/save a file from/to DDR2. We must tell frame
number

By default, in TI DSP, it will enable DDR input/output. In PC, it always
read/write from itself's filesystem.

```sh
$ scripts/burn.js -- build/x264.out --input=../../352x288.yuv --disable-ddr-input
# ...
../../352x288.yuv [info]: 352x288p 0:0 @ 25/1 fps (cfr)
x264 [info]: profile Constrained Baseline, level 1.3
x264 [info]: frame I:1 Avg QP:29.00 size: 5403
encoded 1 frames, 0.02 fps, 1080.60 kb/s
$ scripts/burn.js ../352x288.yuv -- build/x264.out --input=../../352x288.yuv --frames=1
# ...
../../352x288.yuv [info]: 352x288p 0:0 @ 25/1 fps (cfr)
x264 [info]: profile Constrained Baseline, level 1.3
x264 [info]: frame I:1 Avg QP:29.00 size: 5648
encoded 1 frames, 0.50 fps, 1129.60 kb/s
```

### --input/--output

In PC, related path is based on `$PWD`. In TI DSP, related path is based on the
directory of `x264.out`.

```sh
$ build/host/x264 --input=../352x288.yuv
../352x288.yuv [info]: 352x288p 0:0 @ 25/1 fps (cfr)
x264 [info]: profile Constrained Baseline, level 1.3
x264 [info]: frame I:1 Avg QP:29.00 size: 5403
encoded 1 frames, inf fps, 1080.60 kb/s
```

If you use DDR input, it will ignore `--input`. however, `x264` get
`widthxheight` from `--input`. So the following commands are same:

```sh
scripts/burn.js ../352x288.yuv -- build/x264.out --input=../../352x288.yuv --frames=1
scripts/burn.js ../352x288.yuv -- build/x264.out --input=foo352x288bar.yuv --frames=1
```

`scripts/burn.js ../352x288.yuv` will `loadRaw()` `../352x288.yuv` to DDR.
If the power is on, the step only need to be done once:

```sh
scripts/burn.js ../352x288.yuv
scripts/burn.js -- build/x264.out --input=../../352x288.yuv --frames=1
```

### Todo

- Fix bug about 5648 != 5403

## Documents

- codec
Expand Down
61 changes: 39 additions & 22 deletions input.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ typedef struct
uint64_t frame_size; /* frame size in bytes*/
} input_hnd_t;

static int open_file(char *psz_filename, void **p_handle, video_info_t *info) {
static int open_file(char *psz_filename, void **p_handle, video_info_t *info, int b_ddr_input) {
int i;
char *p;
const x264_cli_csp_t *csp;
Expand All @@ -122,14 +122,14 @@ static int open_file(char *psz_filename, void **p_handle, video_info_t *info) {
/* default color-space: I420 without high bit-depth */
info->csp = X264_CSP_I420;

#if 0
if (!strcmp(psz_filename, "-"))
h->fh = stdin;
else
h->fh = fopen(psz_filename, "rb");
if (h->fh == NULL)
return -1;
#endif
if (b_ddr_input == 0) {
if (!strcmp(psz_filename, "-"))
h->fh = stdin;
else
h->fh = fopen(psz_filename, "rb");
if (h->fh == NULL)
return -1;
}

csp = x264_cli_get_csp(info->csp);
for (i = 0; i < csp->planes; i++) {
Expand All @@ -140,6 +140,13 @@ static int open_file(char *psz_filename, void **p_handle, video_info_t *info) {
}

if (h->frame_size > 0) {
if (b_ddr_input == 0) {
uint64_t i_size;
fseek(h->fh, 0, SEEK_END);
i_size = ftell(h->fh);
fseek(h->fh, 0, SEEK_SET);
info->num_frames = i_size / h->frame_size;
}
#ifdef DOWNSAMPLE
info->num_frames /= SCALE * SCALE;
#endif
Expand All @@ -149,7 +156,7 @@ static int open_file(char *psz_filename, void **p_handle, video_info_t *info) {
return 0;
}

static int read_frame_internal(cli_pic_t *pic, input_hnd_t *h) {
static int read_frame_internal(cli_pic_t *pic, input_hnd_t *h, int b_ddr_input) {
int error = 0;
int i;
int pixel_depth = x264_cli_csp_depth_factor(pic->img.csp);
Expand All @@ -167,7 +174,11 @@ static int read_frame_internal(cli_pic_t *pic, input_hnd_t *h) {
}
plane_size *= SCALE * SCALE;
#endif
buf = (void *)p_yuv;
if (b_ddr_input == 0) {
buf = malloc(pixel_depth * plane_size);
error |= fread(buf, pixel_depth, plane_size, h->fh) != plane_size;
} else
buf = (void *)p_yuv;
#ifndef DOWNSAMPLE
memcpy((void *)pic->img.plane[i], buf, plane_size);
#elif DOWNSAMPLE == DOWNSAMPLE_BILINEAR
Expand All @@ -183,29 +194,35 @@ static int read_frame_internal(cli_pic_t *pic, input_hnd_t *h) {
#else
#error wrong DOWNSAMPLE!
#endif
p_yuv += pixel_depth * plane_size;
if (b_ddr_input == 0)
free(buf);
else
p_yuv += pixel_depth * plane_size;
}
return error;
}

static int read_frame(cli_pic_t *pic, void *handle, int i_frame) {
static int read_frame(cli_pic_t *pic, void *handle, int i_frame, int b_ddr_input) {
input_hnd_t *h = handle;

if (read_frame_internal(pic, h))
if (b_ddr_input == 0 && i_frame > h->next_frame)
fseek(h->fh, i_frame * h->frame_size, SEEK_SET);

if (read_frame_internal(pic, h, b_ddr_input))
return -1;

h->next_frame = i_frame + 1;
return 0;
}

static int close_file(void *handle) {
#if 0
input_hnd_t *h = handle;
if (!h || !h->fh)
return 0;
fclose(h->fh);
free(h);
#endif
static int close_file(void *handle, int b_ddr_input) {
if (b_ddr_input == 0) {
input_hnd_t *h = handle;
if (!h || !h->fh)
return 0;
fclose(h->fh);
free(h);
}
return 0;
}

Expand Down
7 changes: 4 additions & 3 deletions input.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef X264_INPUT_H
#define X264_INPUT_H

#include <stdint.h>
/* properties of the source given by the demuxer */
typedef struct
{
Expand Down Expand Up @@ -45,12 +46,12 @@ typedef struct

typedef struct
{
int (*open_file)(char *psz_filename, void **p_handle, video_info_t *info);
int (*open_file)(char *psz_filename, void **p_handle, video_info_t *info, int b_ddr_input);
int (*picture_alloc)(cli_pic_t *pic, int csp, int width, int height);
int (*read_frame)(cli_pic_t *pic, void *handle, int i_frame);
int (*read_frame)(cli_pic_t *pic, void *handle, int i_frame, int b_ddr_input);
int (*release_frame)(cli_pic_t *pic, void *handle);
void (*picture_clean)(cli_pic_t *pic);
int (*close_file)(void *handle);
int (*close_file)(void *handle, int b_ddr_input);
} cli_input_t;

extern const cli_input_t cli_input;
Expand Down
Loading

0 comments on commit 1fcfbef

Please sign in to comment.