loggerd: switch to v4l encoder try 2 (#24380)
* start v4l encoder
* v4l encoder starts
* start and stop
* fill in proper controls
* it dequeued a buffer
* getting bytes
* it made a video
* it does make files
* getting close
* ahh, so that's how dequeue works
* qcam works (no remuxing)
* remuxing works
* we just need to make shutdown and rollover graceful
* graceful destruction
* switch to polling
* should work now
* fix pc build
* refactors, stop properly
* touchups, remove a copy
* add v4l encoder to release
* inlcude file
* move writing to it's own thread
* fix minor memory leak
* block instead of dropping frames
* add counter, fix tests maybe
* better debugging and test print
* print file path in assert
* format string in test
* no more oversized qlogs
* match qcam
* touchups, remove omx encoder
* remove omx include files
* checked ioctl, better debugging, open by name
* unused import
* move linux includes to third_party/linux/include
* simple encoderd
* full packet
* encoderd should be complete
* lagging print
* updates
* name dq thread
* subset idx
* video file writing works
* debug
* potential bugfix
* rotation works
* iframe
* keep writing support
* ci should pass
* loggerd, not encoderd
* remote encoder code
* support remote encoder
* cereal to master, add encoderd
* header no longer required
* put that back there
* realtime
* lower decoder latency
* don't use queue for VisionIpcBufExtra, disable realtime again
* assert all written
* hmm simpler
* only push to to_write if we are writing
* assert timestamp is right
* use at and remove assert
* revert to queue
Co-authored-by: Comma Device <device@comma.ai>
old-commit-hash: 0baa4c3e2ad9ee6f8daba8267db44c2cd44caa62
3 years ago
# include "selfdrive/loggerd/loggerd.h"
# include "selfdrive/loggerd/remote_encoder.h"
int handle_encoder_msg ( LoggerdState * s , Message * msg , std : : string & name , struct RemoteEncoder & re ) {
const LogCameraInfo & cam_info = ( name = = " driverEncodeData " ) ? cameras_logged [ 1 ] :
( ( name = = " wideRoadEncodeData " ) ? cameras_logged [ 2 ] :
( ( name = = " qRoadEncodeData " ) ? qcam_info : cameras_logged [ 0 ] ) ) ;
if ( ! cam_info . record ) return 0 ; // TODO: handle this by not subscribing
// rotation happened, process the queue (happens before the current message)
loggerd: switch to v4l encoder try 2 (#24380)
* start v4l encoder
* v4l encoder starts
* start and stop
* fill in proper controls
* it dequeued a buffer
* getting bytes
* it made a video
* it does make files
* getting close
* ahh, so that's how dequeue works
* qcam works (no remuxing)
* remuxing works
* we just need to make shutdown and rollover graceful
* graceful destruction
* switch to polling
* should work now
* fix pc build
* refactors, stop properly
* touchups, remove a copy
* add v4l encoder to release
* inlcude file
* move writing to it's own thread
* fix minor memory leak
* block instead of dropping frames
* add counter, fix tests maybe
* better debugging and test print
* print file path in assert
* format string in test
* no more oversized qlogs
* match qcam
* touchups, remove omx encoder
* remove omx include files
* checked ioctl, better debugging, open by name
* unused import
* move linux includes to third_party/linux/include
* simple encoderd
* full packet
* encoderd should be complete
* lagging print
* updates
* name dq thread
* subset idx
* video file writing works
* debug
* potential bugfix
* rotation works
* iframe
* keep writing support
* ci should pass
* loggerd, not encoderd
* remote encoder code
* support remote encoder
* cereal to master, add encoderd
* header no longer required
* put that back there
* realtime
* lower decoder latency
* don't use queue for VisionIpcBufExtra, disable realtime again
* assert all written
* hmm simpler
* only push to to_write if we are writing
* assert timestamp is right
* use at and remove assert
* revert to queue
Co-authored-by: Comma Device <device@comma.ai>
old-commit-hash: 0baa4c3e2ad9ee6f8daba8267db44c2cd44caa62
3 years ago
int bytes_count = 0 ;
if ( re . logger_segment ! = s - > rotate_segment ) {
re . logger_segment = s - > rotate_segment ;
for ( auto & qmsg : re . q ) {
bytes_count + = handle_encoder_msg ( s , qmsg , name , re ) ;
}
re . q . clear ( ) ;
}
loggerd: switch to v4l encoder try 2 (#24380)
* start v4l encoder
* v4l encoder starts
* start and stop
* fill in proper controls
* it dequeued a buffer
* getting bytes
* it made a video
* it does make files
* getting close
* ahh, so that's how dequeue works
* qcam works (no remuxing)
* remuxing works
* we just need to make shutdown and rollover graceful
* graceful destruction
* switch to polling
* should work now
* fix pc build
* refactors, stop properly
* touchups, remove a copy
* add v4l encoder to release
* inlcude file
* move writing to it's own thread
* fix minor memory leak
* block instead of dropping frames
* add counter, fix tests maybe
* better debugging and test print
* print file path in assert
* format string in test
* no more oversized qlogs
* match qcam
* touchups, remove omx encoder
* remove omx include files
* checked ioctl, better debugging, open by name
* unused import
* move linux includes to third_party/linux/include
* simple encoderd
* full packet
* encoderd should be complete
* lagging print
* updates
* name dq thread
* subset idx
* video file writing works
* debug
* potential bugfix
* rotation works
* iframe
* keep writing support
* ci should pass
* loggerd, not encoderd
* remote encoder code
* support remote encoder
* cereal to master, add encoderd
* header no longer required
* put that back there
* realtime
* lower decoder latency
* don't use queue for VisionIpcBufExtra, disable realtime again
* assert all written
* hmm simpler
* only push to to_write if we are writing
* assert timestamp is right
* use at and remove assert
* revert to queue
Co-authored-by: Comma Device <device@comma.ai>
old-commit-hash: 0baa4c3e2ad9ee6f8daba8267db44c2cd44caa62
3 years ago
// extract the message
loggerd: switch to v4l encoder try 2 (#24380)
* start v4l encoder
* v4l encoder starts
* start and stop
* fill in proper controls
* it dequeued a buffer
* getting bytes
* it made a video
* it does make files
* getting close
* ahh, so that's how dequeue works
* qcam works (no remuxing)
* remuxing works
* we just need to make shutdown and rollover graceful
* graceful destruction
* switch to polling
* should work now
* fix pc build
* refactors, stop properly
* touchups, remove a copy
* add v4l encoder to release
* inlcude file
* move writing to it's own thread
* fix minor memory leak
* block instead of dropping frames
* add counter, fix tests maybe
* better debugging and test print
* print file path in assert
* format string in test
* no more oversized qlogs
* match qcam
* touchups, remove omx encoder
* remove omx include files
* checked ioctl, better debugging, open by name
* unused import
* move linux includes to third_party/linux/include
* simple encoderd
* full packet
* encoderd should be complete
* lagging print
* updates
* name dq thread
* subset idx
* video file writing works
* debug
* potential bugfix
* rotation works
* iframe
* keep writing support
* ci should pass
* loggerd, not encoderd
* remote encoder code
* support remote encoder
* cereal to master, add encoderd
* header no longer required
* put that back there
* realtime
* lower decoder latency
* don't use queue for VisionIpcBufExtra, disable realtime again
* assert all written
* hmm simpler
* only push to to_write if we are writing
* assert timestamp is right
* use at and remove assert
* revert to queue
Co-authored-by: Comma Device <device@comma.ai>
old-commit-hash: 0baa4c3e2ad9ee6f8daba8267db44c2cd44caa62
3 years ago
capnp : : FlatArrayMessageReader cmsg ( kj : : ArrayPtr < capnp : : word > ( ( capnp : : word * ) msg - > getData ( ) , msg - > getSize ( ) ) ) ;
auto event = cmsg . getRoot < cereal : : Event > ( ) ;
auto edata = ( name = = " driverEncodeData " ) ? event . getDriverEncodeData ( ) :
( ( name = = " wideRoadEncodeData " ) ? event . getWideRoadEncodeData ( ) :
( ( name = = " qRoadEncodeData " ) ? event . getQRoadEncodeData ( ) : event . getRoadEncodeData ( ) ) ) ;
auto idx = edata . getIdx ( ) ;
auto flags = idx . getFlags ( ) ;
if ( ! re . writer ) {
// only create on iframe
if ( flags & V4L2_BUF_FLAG_KEYFRAME ) {
if ( re . dropped_frames ) {
// this should only happen for the first segment, maybe
LOGD ( " %s: dropped %d non iframe packets before init " , name . c_str ( ) , re . dropped_frames ) ;
re . dropped_frames = 0 ;
}
re . writer . reset ( new VideoWriter ( s - > segment_path ,
cam_info . filename , idx . getType ( ) ! = cereal : : EncodeIndex : : Type : : FULL_H_E_V_C ,
cam_info . frame_width , cam_info . frame_height , cam_info . fps , idx . getType ( ) ) ) ;
loggerd: switch to v4l encoder try 2 (#24380)
* start v4l encoder
* v4l encoder starts
* start and stop
* fill in proper controls
* it dequeued a buffer
* getting bytes
* it made a video
* it does make files
* getting close
* ahh, so that's how dequeue works
* qcam works (no remuxing)
* remuxing works
* we just need to make shutdown and rollover graceful
* graceful destruction
* switch to polling
* should work now
* fix pc build
* refactors, stop properly
* touchups, remove a copy
* add v4l encoder to release
* inlcude file
* move writing to it's own thread
* fix minor memory leak
* block instead of dropping frames
* add counter, fix tests maybe
* better debugging and test print
* print file path in assert
* format string in test
* no more oversized qlogs
* match qcam
* touchups, remove omx encoder
* remove omx include files
* checked ioctl, better debugging, open by name
* unused import
* move linux includes to third_party/linux/include
* simple encoderd
* full packet
* encoderd should be complete
* lagging print
* updates
* name dq thread
* subset idx
* video file writing works
* debug
* potential bugfix
* rotation works
* iframe
* keep writing support
* ci should pass
* loggerd, not encoderd
* remote encoder code
* support remote encoder
* cereal to master, add encoderd
* header no longer required
* put that back there
* realtime
* lower decoder latency
* don't use queue for VisionIpcBufExtra, disable realtime again
* assert all written
* hmm simpler
* only push to to_write if we are writing
* assert timestamp is right
* use at and remove assert
* revert to queue
Co-authored-by: Comma Device <device@comma.ai>
old-commit-hash: 0baa4c3e2ad9ee6f8daba8267db44c2cd44caa62
3 years ago
// write the header
auto header = edata . getHeader ( ) ;
re . writer - > write ( ( uint8_t * ) header . begin ( ) , header . size ( ) , idx . getTimestampEof ( ) / 1000 , true , false ) ;
re . segment = idx . getSegmentNum ( ) ;
} else {
+ + re . dropped_frames ;
return bytes_count ;
}
}
if ( re . segment ! = idx . getSegmentNum ( ) ) {
if ( re . writer ) {
// encoder is on the next segment, this segment is over so we close the videowriter
re . writer . reset ( ) ;
+ + s - > ready_to_rotate ;
LOGD ( " rotate %d -> %d ready %d/%d " , re . segment , idx . getSegmentNum ( ) , s - > ready_to_rotate . load ( ) , s - > max_waiting ) ;
}
// queue up all the new segment messages, they go in after the rotate
re . q . push_back ( msg ) ;
} else {
auto data = edata . getData ( ) ;
re . writer - > write ( ( uint8_t * ) data . begin ( ) , data . size ( ) , idx . getTimestampEof ( ) / 1000 , false , flags & V4L2_BUF_FLAG_KEYFRAME ) ;
// put it in log stream as the idx packet
MessageBuilder bmsg ;
auto evt = bmsg . initEvent ( event . getValid ( ) ) ;
evt . setLogMonoTime ( event . getLogMonoTime ( ) ) ;
if ( name = = " driverEncodeData " ) { evt . setDriverEncodeIdx ( idx ) ; }
if ( name = = " wideRoadEncodeData " ) { evt . setWideRoadEncodeIdx ( idx ) ; }
if ( name = = " qRoadEncodeData " ) { evt . setQRoadEncodeIdx ( idx ) ; }
if ( name = = " roadEncodeData " ) { evt . setRoadEncodeIdx ( idx ) ; }
auto new_msg = bmsg . toBytes ( ) ;
logger_log ( & s - > logger , ( uint8_t * ) new_msg . begin ( ) , new_msg . size ( ) , true ) ; // always in qlog?
bytes_count + = new_msg . size ( ) ;
// this frees the message
delete msg ;
loggerd: switch to v4l encoder try 2 (#24380)
* start v4l encoder
* v4l encoder starts
* start and stop
* fill in proper controls
* it dequeued a buffer
* getting bytes
* it made a video
* it does make files
* getting close
* ahh, so that's how dequeue works
* qcam works (no remuxing)
* remuxing works
* we just need to make shutdown and rollover graceful
* graceful destruction
* switch to polling
* should work now
* fix pc build
* refactors, stop properly
* touchups, remove a copy
* add v4l encoder to release
* inlcude file
* move writing to it's own thread
* fix minor memory leak
* block instead of dropping frames
* add counter, fix tests maybe
* better debugging and test print
* print file path in assert
* format string in test
* no more oversized qlogs
* match qcam
* touchups, remove omx encoder
* remove omx include files
* checked ioctl, better debugging, open by name
* unused import
* move linux includes to third_party/linux/include
* simple encoderd
* full packet
* encoderd should be complete
* lagging print
* updates
* name dq thread
* subset idx
* video file writing works
* debug
* potential bugfix
* rotation works
* iframe
* keep writing support
* ci should pass
* loggerd, not encoderd
* remote encoder code
* support remote encoder
* cereal to master, add encoderd
* header no longer required
* put that back there
* realtime
* lower decoder latency
* don't use queue for VisionIpcBufExtra, disable realtime again
* assert all written
* hmm simpler
* only push to to_write if we are writing
* assert timestamp is right
* use at and remove assert
* revert to queue
Co-authored-by: Comma Device <device@comma.ai>
old-commit-hash: 0baa4c3e2ad9ee6f8daba8267db44c2cd44caa62
3 years ago
}
return bytes_count ;
}