// client sends raw video data via this endpoint
client sends raw video data via this endpoint
client sends raw video data via this endpoint
async fn post_segment_data(
    request_id: Uuid,
    _auth: (),
    body: Bytes,
    temp_dir: Option<PathBuf>,
) -> Result<impl Reply, Rejection> {
    if let Some(item) = ENCODER_QUEUE.read().get(&request_id) {
        let mut item_handle = item.write();
        let frame_data;
        let keyframe_number_outer;
        let next_analysis_frame_outer;
        let segment_idx_outer;
        if let EncodeState::AwaitingData {
            keyframe_number,
            next_analysis_frame,
            segment_idx,
            ..
        } = &mut item_handle.state
        {
            keyframe_number_outer = *keyframe_number;
            next_analysis_frame_outer = *next_analysis_frame;
            segment_idx_outer = *segment_idx;
            let compressed_frames: Vec<Vec<u8>> = try_or_500!(bincode::deserialize(&body));
            frame_data = match temp_dir {
                Some(temp_dir) => {
                    let frame_count = compressed_frames.len();
                    let mut temp_path = temp_dir;
                    temp_path.push(request_id.to_hyphenated().to_string());
                    temp_path.set_extension("py4m");
                    let file = File::create(&temp_path).unwrap();
                    let mut writer = BufWriter::new(file);
                    for frame in compressed_frames {
                        let frame_data = if item_handle.video_info.bit_depth == 8 {
                            bincode::serialize(&decompress_frame::<u8>(&frame)).unwrap()
                        } else {
                            bincode::serialize(&decompress_frame::<u16>(&frame)).unwrap()
                        };
                        writer
                            .write_u32::<LittleEndian>(frame_data.len() as u32)
                            .unwrap();
                        writer.write_all(&frame_data).unwrap();
                    }
                    writer.flush().unwrap();
                    SegmentFrameData::Y4MFile {
                        path: temp_path,
                        frame_count,
                    }
                }
                None => SegmentFrameData::CompressedFrames(compressed_frames),
            }
        } else {
            return Ok(warp::reply::with_status(
                warp::reply::json(&()),
                StatusCode::NOT_FOUND,
            ));
        }
        item_handle.state = EncodeState::Ready {
            keyframe_number: keyframe_number_outer,
            next_analysis_frame: next_analysis_frame_outer,
            segment_idx: segment_idx_outer,
            raw_frames: Arc::new(frame_data),
        };
        return Ok(warp::reply::with_status(
            warp::reply::json(&()),
            StatusCode::OK,
        ));
    }
    Ok(warp::reply::with_status(
        warp::reply::json(&()),
        StatusCode::NOT_FOUND,
    ))
}
async fn post_segment_data ( request_id : Uuid , _auth : ( ) , body : Bytes , temp_dir : Option < PathBuf > , ) -> Result < impl Reply , Rejection > { if let Some ( item ) = ENCODER_QUEUE . read ( ) . get ( & request_id ) { let mut item_handle = item . write ( ) ; let frame_data ; let keyframe_number_outer ; let next_analysis_frame_outer ; let segment_idx_outer ; if let EncodeState :: AwaitingData { keyframe_number , next_analysis_frame , segment_idx , .. } = & mut item_handle . state { keyframe_number_outer = * keyframe_number ; next_analysis_frame_outer = * next_analysis_frame ; segment_idx_outer = * segment_idx ; let compressed_frames : Vec < Vec < u8 > > = try_or_500 ! ( bincode deserialize ( body ) ) ; frame_data = match temp_dir { Some ( temp_dir ) => { let frame_count = compressed_frames . len ( ) ; let mut temp_path = temp_dir ; temp_path . push ( request_id . to_hyphenated ( ) . to_string ( ) ) ; temp_path . set_extension ( " " ) ; let file = File :: create ( & temp_path ) . unwrap ( ) ; let mut writer = BufWriter :: new ( file ) ; for frame in compressed_frames { let frame_data = if item_handle . video_info . bit_depth == 8 { bincode :: serialize ( & decompress_frame :: < u8 > ( & frame ) ) . unwrap ( ) } else { bincode :: serialize ( & decompress_frame :: < u16 > ( & frame ) ) . unwrap ( ) } ; writer . write_u32 :: < LittleEndian > ( frame_data . len ( ) as u32 ) . unwrap ( ) ; writer . write_all ( & frame_data ) . unwrap ( ) ; } writer . flush ( ) . unwrap ( ) ; SegmentFrameData :: Y4MFile { path : temp_path , frame_count , } } None => SegmentFrameData :: CompressedFrames ( compressed_frames ) , } } else { return Ok ( warp :: reply :: with_status ( warp :: reply :: json ( & ( ) ) , StatusCode :: NOT_FOUND , ) ) ; } item_handle . state = EncodeState :: Ready { keyframe_number : keyframe_number_outer , next_analysis_frame : next_analysis_frame_outer , segment_idx : segment_idx_outer , raw_frames : Arc :: new ( frame_data ) , } ; return Ok ( warp :: reply :: with_status ( warp :: reply :: json ( & ( ) ) , StatusCode :: OK , ) ) ; } Ok ( warp :: reply :: with_status ( warp :: reply :: json ( & ( ) ) , StatusCode :: NOT_FOUND , ) ) }
client sends raw video data via this endpoint
client sends raw video data via this endpoint
request_id
Uuid
_auth
()
body
Bytes
temp_dir
Option<PathBuf>