video: video-info: fix Display implementations

We were calling the blanket implementation of ToString, which is using
Display, rather than our own, resulting in an infinite recursion.

Also a couple of to_string() implementation were using the wrong
glib conversion as they actually return a 'const gchar *'.
This commit is contained in:
Guillaume Desmottes 2019-06-18 15:45:33 +05:30
parent e81b5717e9
commit cd16337874

View file

@ -188,7 +188,7 @@ impl fmt::Debug for ::VideoColorimetry {
impl fmt::Display for ::VideoColorimetry { impl fmt::Display for ::VideoColorimetry {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str(&self.to_string()) f.write_str(&::VideoColorimetry::to_string(self))
} }
} }
@ -787,7 +787,7 @@ impl glib::translate::FromGlibPtrFull<*mut gst_video_sys::GstVideoInfo> for Vide
impl ::VideoFieldOrder { impl ::VideoFieldOrder {
pub fn to_string(self) -> String { pub fn to_string(self) -> String {
unsafe { unsafe {
from_glib_full(gst_video_sys::gst_video_field_order_to_string( from_glib_none(gst_video_sys::gst_video_field_order_to_string(
self.to_glib(), self.to_glib(),
)) ))
} }
@ -817,14 +817,14 @@ impl str::FromStr for ::VideoFieldOrder {
#[cfg(any(feature = "v1_12", feature = "dox"))] #[cfg(any(feature = "v1_12", feature = "dox"))]
impl fmt::Display for ::VideoFieldOrder { impl fmt::Display for ::VideoFieldOrder {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str(&self.to_string()) f.write_str(&::VideoFieldOrder::to_string(*self))
} }
} }
impl ::VideoInterlaceMode { impl ::VideoInterlaceMode {
pub fn to_string(self) -> String { pub fn to_string(self) -> String {
unsafe { unsafe {
from_glib_full(gst_video_sys::gst_video_interlace_mode_to_string( from_glib_none(gst_video_sys::gst_video_interlace_mode_to_string(
self.to_glib(), self.to_glib(),
)) ))
} }
@ -852,7 +852,7 @@ impl str::FromStr for ::VideoInterlaceMode {
impl fmt::Display for ::VideoInterlaceMode { impl fmt::Display for ::VideoInterlaceMode {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str(&self.to_string()) f.write_str(&::VideoInterlaceMode::to_string(*self))
} }
} }
@ -951,4 +951,14 @@ mod tests {
assert_eq!(info.stride(), [1928, 1928]); assert_eq!(info.stride(), [1928, 1928]);
assert_eq!(info.offset(), [0, 2082240]); assert_eq!(info.offset(), [0, 2082240]);
} }
#[cfg(any(feature = "v1_12", feature = "dox"))]
#[test]
fn test_display() {
gst::init().unwrap();
format!("{}", ::VideoColorimetry::from_string("sRGB").unwrap());
format!("{}", ::VideoFieldOrder::TopFieldFirst);
format!("{}", ::VideoInterlaceMode::Progressive);
}
} }