Skip to content

Commit

Permalink
return back stream bounds update
Browse files Browse the repository at this point in the history
  • Loading branch information
rassokhin-s committed Aug 15, 2023
1 parent 2f0c2d7 commit 750c35a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
40 changes: 40 additions & 0 deletions core/internal/ingest/post.int.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,46 @@ describe('POST internal/ingest/streams/:id/stream-source-file-and-segments', ()
expect(streamSegments.length).toBe(0)
})

describe('stream bounds update', () => {
test('stream start, end and max_sample_rate are set for empty stream', async () => {
await commonSetup()
await request(app).post(`/streams/${stream.id}/stream-source-file-and-segments`).send(testPayload)

const streamFromDb = await models.Stream.findOne({ where: { id: stream.id } })
expect(streamFromDb.maxSampleRate).toBe(testPayload.stream_source_file.sample_rate)
expect(streamFromDb.start).toEqual(moment.utc(testPayload.stream_segments[0].start).toDate())
expect(streamFromDb.end).toEqual(moment.utc(testPayload.stream_segments[0].end).toDate())
})

test('stream start, end and max_sample_rate are updated if new values are bigger/smaller', async () => {
await commonSetup()
const stream = await models.Stream.create(
{ id: 'abcdsaqwery2', name: 'my stream 2', createdById: seedValues.primaryUserId, start: '2021-04-18T12:12:10.000Z', end: '2021-04-18T12:12:20.000Z', maxSampleRate: 24000 }
)

await request(app).post(`/streams/${stream.id}/stream-source-file-and-segments`).send(testPayload)

const streamFromDb = await models.Stream.findOne({ where: { id: stream.id } })
expect(streamFromDb.maxSampleRate).toBe(testPayload.stream_source_file.sample_rate)
expect(streamFromDb.start).toEqual(moment.utc(testPayload.stream_segments[0].start).toDate())
expect(streamFromDb.end).toEqual(moment.utc(testPayload.stream_segments[0].end).toDate())
})

test('stream start, end and max_sample_rate are not updated if new values are not bigger/smaller', async () => {
await commonSetup()
const stream = await models.Stream.create(
{ id: 'abcdsaqwery3', name: 'my stream 3', createdById: seedValues.primaryUserId, start: '2020-01-01 00:00:00', end: '2021-05-05 00:00:00', maxSampleRate: 128000 }
)

await request(app).post(`/streams/${stream.id}/stream-source-file-and-segments`).send(testPayload)

const streamFromDb = await models.Stream.findOne({ where: { id: stream.id } })
expect(streamFromDb.maxSampleRate).toBe(stream.maxSampleRate)
expect(streamFromDb.start).toEqual(moment.utc(stream.start).toDate())
expect(streamFromDb.end).toEqual(moment.utc(stream.end).toDate())
})
})

test('validation error is returned if user tries to upload another file with existing start', async () => {
await commonSetup()
const sourceFile = await models.StreamSourceFile.create({ stream_id: stream.id, sha1_checksum: testPayload.stream_source_file.sha1_checksum, filename: testPayload.stream_source_file.filename, duration: testPayload.stream_source_file.duration, sample_count: testPayload.stream_source_file.sample_count, sample_rate: testPayload.stream_source_file.sample_rate, channels_count: testPayload.stream_source_file.channels_count, bit_rate: testPayload.stream_source_file.bit_rate, audio_codec_id: audioCodecId, audio_file_format_id: audioFileFormatId })
Expand Down
10 changes: 9 additions & 1 deletion core/internal/ingest/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = function (req, res) {
const sfParams = await sfConverter.validate() // validate stream_source_file attributes
const transformedArray = await segConverter.validate() // validate stream_segment[] attributes

await streamDao.get(streamId, { transaction })
const stream = await streamDao.get(streamId, { transaction })
// Set missing stream_source_file attributes and create a db row
sfParams.stream_id = streamId
streamSourceFileDao.transformMetaAttr(sfParams)
Expand Down Expand Up @@ -123,6 +123,14 @@ module.exports = function (req, res) {
return a < b
})

// Refresh stream max_sample rate, start and end if needed
const maxEnd = moment.max(transformedArray.map(s => s.end))
await streamDao.refreshStreamBoundVars(stream, {
start: minStart.toDate(),
end: maxEnd.toDate(),
sampleRate: streamSourceFile.sample_rate
}, { transaction })

if (arbimonService.isEnabled && createdSegments.length) {
await arbimonService.createRecordingsFromSegments(sfParams, createdSegments, { transaction })
}
Expand Down

0 comments on commit 750c35a

Please sign in to comment.