mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 07:02:44 +00:00 
			
		
		
		
	LibVideo: Give Matroska duration an absolute value getter
Previously, the duration had to be multiplied by timestamp_scale and converted to a Time object, now SegmentInformation::duration() does it itself.
This commit is contained in:
		
							parent
							
								
									a58bf7c3d1
								
							
						
					
					
						commit
						2a9fb8b439
					
				
					 3 changed files with 13 additions and 9 deletions
				
			
		|  | @ -31,14 +31,20 @@ public: | |||
|     void set_muxing_app(String muxing_app) { m_muxing_app = move(muxing_app); } | ||||
|     Utf8View writing_app() const { return Utf8View(m_writing_app); } | ||||
|     void set_writing_app(String writing_app) { m_writing_app = move(writing_app); } | ||||
|     Optional<double> duration() const { return m_duration; } | ||||
|     void set_duration(double duration) { m_duration.emplace(duration); } | ||||
|     Optional<double> duration_unscaled() const { return m_duration_unscaled; } | ||||
|     void set_duration_unscaled(double duration) { m_duration_unscaled.emplace(duration); } | ||||
|     Optional<Time> duration() const | ||||
|     { | ||||
|         if (!duration_unscaled().has_value()) | ||||
|             return {}; | ||||
|         return Time::from_nanoseconds(static_cast<i64>(static_cast<double>(timestamp_scale()) * duration_unscaled().value())); | ||||
|     } | ||||
| 
 | ||||
| private: | ||||
|     u64 m_timestamp_scale { 1'000'000 }; | ||||
|     String m_muxing_app; | ||||
|     String m_writing_app; | ||||
|     Optional<double> m_duration; | ||||
|     Optional<double> m_duration_unscaled; | ||||
| }; | ||||
| 
 | ||||
| class TrackEntry { | ||||
|  |  | |||
|  | @ -82,10 +82,8 @@ DecoderErrorOr<NonnullOwnPtr<Sample>> MatroskaDemuxer::get_next_sample_for_track | |||
| 
 | ||||
| DecoderErrorOr<Time> MatroskaDemuxer::duration() | ||||
| { | ||||
|     auto segment_information = TRY(m_reader.segment_information()); | ||||
|     if (!segment_information.duration().has_value()) | ||||
|         return Time::zero(); | ||||
|     return Time::from_nanoseconds(static_cast<i64>(segment_information.duration().value() * segment_information.timestamp_scale())); | ||||
|     auto duration = TRY(m_reader.segment_information()).duration(); | ||||
|     return duration.value_or(Time::zero()); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -270,8 +270,8 @@ static DecoderErrorOr<SegmentInformation> parse_information(Streamer& streamer) | |||
|             dbgln_if(MATROSKA_DEBUG, "Read WritingApp attribute: {}", segment_information.writing_app().as_string()); | ||||
|             break; | ||||
|         case DURATION_ID: | ||||
|             segment_information.set_duration(TRY_READ(streamer.read_float())); | ||||
|             dbgln_if(MATROSKA_DEBUG, "Read Duration attribute: {}", segment_information.duration().value()); | ||||
|             segment_information.set_duration_unscaled(TRY_READ(streamer.read_float())); | ||||
|             dbgln_if(MATROSKA_DEBUG, "Read Duration attribute: {}", segment_information.duration_unscaled().value()); | ||||
|             break; | ||||
|         default: | ||||
|             TRY_READ(streamer.read_unknown_element()); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Zaggy1024
						Zaggy1024