summaryrefslogtreecommitdiff
path: root/include/hm12.h
diff options
context:
space:
mode:
authorCharlie Root <root@dangofactory.local>2026-10-25 10:15:31 +0900
committerCharlie Root <root@dangofactory.local>2026-10-25 10:15:31 +0900
commit7318435b737394904bb1c5ce9fe013b0eee1882f (patch)
tree41adf14909f5f8d15c8e1c5db361e6ea0ac97598 /include/hm12.h
downloadmpegcap-baseline-1016.tar.gz
mpegcap-baseline-1016.zip
kare / spoon - CX23416 + FX2 USB MPEG capture toolHEADbaseline-1016
Capture tool for the I-O DATA GV-MVP/RZ2 (04bb:0514): Conexant CX23416 MPEG encoder behind an EZ-USB FX2 bridge, with a CX25837 video decoder (I2C 0x44) and a WM8739 audio ADC (I2C 0x1a). libusb-1.0, C99, built with GNU make on FreeBSD/Linux. kare capture: MPEG-2 PS or raw HM12 (y4m), MPEG audio, --pcm WAV, live parameter control through CTLFILE spoon live viewer: pipe -> ffmpeg -> SDL2, clickable control bar, resizable window, raw PCM playback on -r State at this commit: - MPEG-2 PS 720x480 ~6.5 Mbit/s, colour, mp2 48 kHz stereo 224 kbit/s - raw HM12 (NV12_16L16, 518,416-byte frames) with selective median denoise - S-Video works: luma In1 + chroma In5 (0x103=0xd0); RCA is In2+In6 (0xe1) - VBI cropped: 0x0474=24 with 0x0477=28 (they must move together, +4) - audio: never issue an I2C READ to the WM8739 (write-only part) History note: this repository was squashed to a single commit on 2026-10-25 because the earlier history carried the CX23416 firmware images and the vendor trees. Those still exist on the working copy (firmware/, ref/) and are in .gitignore; only src/, include/, Makefile, README.md and .gitignore are versioned. The pre-squash history is preserved locally as a bundle.
Diffstat (limited to 'include/hm12.h')
-rw-r--r--include/hm12.h88
1 files changed, 88 insertions, 0 deletions
diff --git a/include/hm12.h b/include/hm12.h
new file mode 100644
index 0000000..c88a730
--- /dev/null
+++ b/include/hm12.h
@@ -0,0 +1,88 @@
+/*
+ * hm12.h - HM12 raw YUV 4:2:0 handling
+ */
+#ifndef PVR2_HM12_H
+#define PVR2_HM12_H
+
+#include <stdio.h>
+#include <stddef.h>
+
+/* 1 = apply the light luma filter to the raw planes (see hm12.c). The -N
+ * command-line flag clears it so the filter can be A/B'd against the
+ * unfiltered picture on the same source. */
+extern int hm12_filter;
+extern int hm12_hfilter;
+
+/* y4m interlace tag: 0 = progressive (Ip), 1 = top field first (It),
+ * 2 = bottom field first (Ib). Measured on this hardware the raw stream
+ * is progressive - lines within a frame differ by 3.95 while the same
+ * field across two frames differs by 13.98, i.e. the fields are not
+ * separated in time - so Ip is the default. Selectable for testing. */
+extern int hm12_interlace;
+
+/* Distance used by the vertical 1-2-1 pass. 1 = neighbouring lines
+ * (right for progressive material), 2 = same field, two lines away
+ * (right if the stream really were interlaced). */
+extern int hm12_vstep;
+
+/*
+ * Luma-only output, for checking vertical-line artefacts.
+ *
+ * The user wants to confirm whether the "jaggedness" is really vertical
+ * lines by looking at the Y plane on its own. This writes a plain
+ * greyscale YUV4MPEG2 at full 720x480: the luma goes in the Y slot and
+ * both chroma planes are held neutral, so VLC (or ffmpeg) shows it as a
+ * greyscale picture with no colour cast to confuse the reading.
+ *
+ * Returns 0 on success, -1 on failure.
+ */
+int hm12_luma_open(const char *path);
+int hm12_luma_write(const unsigned char *y, int w, int h);
+void hm12_luma_close(void);
+
+/*
+ * Per-plane debug output.
+ *
+ * An HM12 conversion can be subtly wrong - a swapped U/V pair, a chroma
+ * tile of the wrong size, a missing de-interleave - and the composite
+ * still looks like video, just with the wrong colours. Dumping each
+ * plane separately makes that obvious: the luma should be a sharp
+ * picture, and the two chroma planes should trace the same shapes as the
+ * luma (at half resolution) rather than scattering.
+ *
+ * YUV4MPEG2 is used rather than PGM so the result can just be opened in
+ * VLC (which PGM is not). Each plane is written as its own video with
+ * the other two held at neutral, so a viewer shows it as greyscale:
+ *
+ * PFX.Y.y4m luma in the Y slot, U=V=128
+ * PFX.U.y4m Cb in the U slot, Y=128, V=128
+ * PFX.V.y4m Cr in the V slot, Y=128, U=128
+ * PFX.uv.y4m (U-128)*4+128 in U and (V-128)*4+128 in V, so a single
+ * view shows the colour cast direction: too blue means the
+ * U/V pair is the wrong way round
+ *
+ * All four are full 720x480 YUV4MPEG2 files: the chroma planes are
+ * upsampled to luma size so each file is a well-formed video of the same
+ * dimensions (a 360x240 header carrying 720x480 data would be rejected by
+ * the demuxer).
+ *
+ * Every frame is appended, so the files play straight through.
+ *
+ * Returns 0 on success, -1 on failure.
+ */
+int hm12_planes_open(const char *prefix);
+int hm12_planes_write(const unsigned char *y, const unsigned char *u,
+ const unsigned char *v, int w, int h);
+void hm12_planes_close(void);
+
+void hm12_de_macro_y(unsigned char *dst, unsigned char *src,
+ int dstride, int w, int h);
+void hm12_de_macro_uv(unsigned char *dstu, unsigned char *dstv,
+ unsigned char *src, int dstride, int w, int h);
+size_t hm12_frame_size(int w, int h);
+int hm12_write_y4m_header(FILE *f, int w, int h, unsigned int fps_num,
+ unsigned int fps_den);
+int hm12_write_frame_y4m(FILE *f, const unsigned char *hm12, int w, int h,
+ unsigned char *scratch);
+
+#endif