Skip to content

Commit

Permalink
feat: support DRI in JPEG depay
Browse files Browse the repository at this point in the history
Support DRI in MJPEG by adding the correct DRI headers when required.

Adjusted the simple camera example so the canvas keeps its aspect ratio.
  • Loading branch information
Tigge authored and steabert committed Oct 29, 2021
1 parent 067a574 commit 877dbaf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/browser/camera/simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
</div>
<div style="position: fixed; width: 1280px; height: 720px">
<video
style="position: absolute; width: 100%; height: 100%;"
style="width: 100%; height: 100%; object-fit: contain"
autoplay
></video>
<canvas style="position: absolute; width: 100%; height: 100%;"></canvas>
<canvas style="width: 100%; height: 100%; object-fit: contain"></canvas>
</div>
<script src="../media-stream-library.min.js"></script>
<script src="simple-player.js"></script>
Expand Down
4 changes: 4 additions & 0 deletions lib/components/jpegdepay/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,7 @@ export function makeScanHeader() {
0,
])
}

export function makeDRIHeader(dri: number) {
return Buffer.from([0xff, 0xdd, 0x00, 4, dri >> 8, dri & 0xff])
}
7 changes: 4 additions & 3 deletions lib/components/jpegdepay/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
makeScanHeader,
makeQuantHeader,
makeFrameHeader,
makeDRIHeader,
} from './headers'
import { payload } from '../../utils/protocols/rtp'
import { makeQtable } from './make-qtable'
Expand Down Expand Up @@ -115,9 +116,8 @@ export function jpegDepayFactory(defaultWidth = 0, defaultHeight = 0) {

const quantHeader = makeQuantHeader(precision, qTable)

if (metadata.DRI !== 0) {
throw new Error('not implemented: DRI')
}
const driHeader =
metadata.DRI === 0 ? Buffer.alloc(0) : makeDRIHeader(metadata.DRI)

const frameHeader = makeFrameHeader(width, height, type)

Expand All @@ -126,6 +126,7 @@ export function jpegDepayFactory(defaultWidth = 0, defaultHeight = 0) {
data: Buffer.concat([
IMAGE_HEADER,
quantHeader,
driHeader,
frameHeader,
HUFFMAN_HEADER,
SCAN_HEADER,
Expand Down

0 comments on commit 877dbaf

Please sign in to comment.