Improved management of failed sources

Clone is failed if its origin is failed, handle MediaPlayer visitor and error message when fail, get SourceList of non-failed sources of a list.
This commit is contained in:
Bruno Herbelin
2023-01-29 10:50:00 +01:00
parent e69ac7ca28
commit 0051533ac8
7 changed files with 81 additions and 60 deletions

View File

@@ -22,7 +22,7 @@ public:
void replay () override; void replay () override;
guint64 playtime () const override; guint64 playtime () const override;
uint texture() const override; uint texture() const override;
bool failed() const override { return origin_ == nullptr; } bool failed() const override { return origin_ == nullptr || origin_->failed(); }
void accept (Visitor& v) override; void accept (Visitor& v) override;
void render() override; void render() override;
glm::ivec2 icon() const override; glm::ivec2 icon() const override;

View File

@@ -157,72 +157,74 @@ MediaInfo MediaPlayer::UriDiscoverer(const std::string &uri)
} }
break; break;
default: default:
case GST_DISCOVERER_OK:
break; break;
} }
// get videos in information found
GList *streams = gst_discoverer_info_get_video_streams(info); if ( result == GST_DISCOVERER_OK ) {
if ( g_list_length(streams) > 0) { // get videos in information found
GList *tmp; GList *streams = gst_discoverer_info_get_video_streams(info);
for (tmp = streams; tmp && !video_stream_info.valid; tmp = tmp->next ) { if ( g_list_length(streams) > 0) {
GstDiscovererStreamInfo *tmpinf = (GstDiscovererStreamInfo *) tmp->data; GList *tmp;
if ( GST_IS_DISCOVERER_VIDEO_INFO(tmpinf) ) for (tmp = streams; tmp && !video_stream_info.valid; tmp = tmp->next ) {
{ GstDiscovererStreamInfo *tmpinf = (GstDiscovererStreamInfo *) tmp->data;
// found a video / image stream : fill-in information if ( GST_IS_DISCOVERER_VIDEO_INFO(tmpinf) )
GstDiscovererVideoInfo* vinfo = GST_DISCOVERER_VIDEO_INFO(tmpinf); {
video_stream_info.width = gst_discoverer_video_info_get_width(vinfo); // found a video / image stream : fill-in information
video_stream_info.height = gst_discoverer_video_info_get_height(vinfo); GstDiscovererVideoInfo* vinfo = GST_DISCOVERER_VIDEO_INFO(tmpinf);
guint parn = gst_discoverer_video_info_get_par_num(vinfo); video_stream_info.width = gst_discoverer_video_info_get_width(vinfo);
guint pard = gst_discoverer_video_info_get_par_denom(vinfo); video_stream_info.height = gst_discoverer_video_info_get_height(vinfo);
video_stream_info.par_width = (video_stream_info.width * parn) / pard; guint parn = gst_discoverer_video_info_get_par_num(vinfo);
video_stream_info.interlaced = gst_discoverer_video_info_is_interlaced(vinfo); guint pard = gst_discoverer_video_info_get_par_denom(vinfo);
video_stream_info.bitrate = gst_discoverer_video_info_get_bitrate(vinfo); video_stream_info.par_width = (video_stream_info.width * parn) / pard;
video_stream_info.isimage = gst_discoverer_video_info_is_image(vinfo); video_stream_info.interlaced = gst_discoverer_video_info_is_interlaced(vinfo);
// if its a video, set duration, framerate, etc. video_stream_info.bitrate = gst_discoverer_video_info_get_bitrate(vinfo);
if ( !video_stream_info.isimage ) { video_stream_info.isimage = gst_discoverer_video_info_is_image(vinfo);
video_stream_info.end = gst_discoverer_info_get_duration (info) ; // if its a video, set duration, framerate, etc.
video_stream_info.seekable = gst_discoverer_info_get_seekable (info); if ( !video_stream_info.isimage ) {
video_stream_info.framerate_n = gst_discoverer_video_info_get_framerate_num(vinfo); video_stream_info.end = gst_discoverer_info_get_duration (info) ;
video_stream_info.framerate_d = gst_discoverer_video_info_get_framerate_denom(vinfo); video_stream_info.seekable = gst_discoverer_info_get_seekable (info);
if (video_stream_info.framerate_n == 0 || video_stream_info.framerate_d == 0) { video_stream_info.framerate_n = gst_discoverer_video_info_get_framerate_num(vinfo);
Log::Info("'%s': No framerate indicated in the file; using default 30fps", uri.c_str()); video_stream_info.framerate_d = gst_discoverer_video_info_get_framerate_denom(vinfo);
video_stream_info.framerate_n = 30; if (video_stream_info.framerate_n == 0 || video_stream_info.framerate_d == 0) {
video_stream_info.framerate_d = 1; Log::Info("'%s': No framerate indicated in the file; using default 30fps", uri.c_str());
video_stream_info.framerate_n = 30;
video_stream_info.framerate_d = 1;
}
video_stream_info.dt = ( (GST_SECOND * static_cast<guint64>(video_stream_info.framerate_d)) / (static_cast<guint64>(video_stream_info.framerate_n)) );
// confirm (or infirm) that its not a single frame
if ( video_stream_info.end < video_stream_info.dt * 2)
video_stream_info.isimage = true;
} }
video_stream_info.dt = ( (GST_SECOND * static_cast<guint64>(video_stream_info.framerate_d)) / (static_cast<guint64>(video_stream_info.framerate_n)) ); // try to fill-in the codec information
// confirm (or infirm) that its not a single frame GstCaps *caps = gst_discoverer_stream_info_get_caps (tmpinf);
if ( video_stream_info.end < video_stream_info.dt * 2) if (caps) {
video_stream_info.isimage = true; gchar *codecstring = gst_pb_utils_get_codec_description(caps);
video_stream_info.codec_name = std::string( codecstring );
g_free(codecstring);
gst_caps_unref (caps);
}
const GstTagList *tags = gst_discoverer_stream_info_get_tags(tmpinf);
if ( tags ) {
gchar *container = NULL;
if ( gst_tag_list_get_string (tags, GST_TAG_CONTAINER_FORMAT, &container) )
video_stream_info.codec_name += ", " + std::string(container);
if (container)
g_free(container);
}
// exit loop
// inform that it succeeded
video_stream_info.valid = true;
} }
// try to fill-in the codec information
GstCaps *caps = gst_discoverer_stream_info_get_caps (tmpinf);
if (caps) {
gchar *codecstring = gst_pb_utils_get_codec_description(caps);
video_stream_info.codec_name = std::string( codecstring );
g_free(codecstring);
gst_caps_unref (caps);
}
const GstTagList *tags = gst_discoverer_stream_info_get_tags(tmpinf);
if ( tags ) {
gchar *container = NULL;
if ( gst_tag_list_get_string (tags, GST_TAG_CONTAINER_FORMAT, &container) )
video_stream_info.codec_name += ", " + std::string(container);
if (container)
g_free(container);
}
// exit loop
// inform that it succeeded
video_stream_info.valid = true;
} }
if (!video_stream_info.valid)
Log::Warning("'%s': Invalid video stream", uri.c_str());
} }
else
Log::Warning("'%s': No video stream", uri.c_str());
if (!video_stream_info.valid) gst_discoverer_stream_info_list_free(streams);
Log::Warning("'%s': Invalid video stream", uri.c_str());
} }
else
Log::Warning("'%s': No supported video stream", uri.c_str());
gst_discoverer_stream_info_list_free(streams);
if (info) if (info)
gst_discoverer_info_unref (info); gst_discoverer_info_unref (info);

View File

@@ -638,7 +638,8 @@ void SessionVisitor::visit (MediaSource& s)
if (!sessionFilePath_.empty()) if (!sessionFilePath_.empty())
uri->SetAttribute("relative", SystemToolkit::path_relative_to_path(s.path(), sessionFilePath_).c_str()); uri->SetAttribute("relative", SystemToolkit::path_relative_to_path(s.path(), sessionFilePath_).c_str());
s.mediaplayer()->accept(*this); if (!s.failed())
s.mediaplayer()->accept(*this);
} }
void SessionVisitor::visit (SessionFileSource& s) void SessionVisitor::visit (SessionFileSource& s)

View File

@@ -109,6 +109,7 @@ public:
// cloning mechanism // cloning mechanism
virtual CloneSource *clone (uint64_t id = 0); virtual CloneSource *clone (uint64_t id = 0);
inline bool cloned() const { return !clones_.empty(); }
// Display mode // Display mode
typedef enum { typedef enum {

View File

@@ -45,6 +45,18 @@ SourceList playable_only (const SourceList &list)
return pl; return pl;
} }
bool isfailed (const Source *s) { return s->failed(); }
SourceList valid_only (const SourceList &list)
{
SourceList pl = list;
pl.remove_if(isfailed);
return pl;
}
bool notactive (const Source *s) { return !s->active(); } bool notactive (const Source *s) { return !s->active(); }
SourceList active_only (const SourceList &list) SourceList active_only (const SourceList &list)

View File

@@ -12,6 +12,7 @@ typedef std::list<Source *> SourceList;
typedef std::list<SourceCore *> SourceCoreList; typedef std::list<SourceCore *> SourceCoreList;
SourceList playable_only (const SourceList &list); SourceList playable_only (const SourceList &list);
SourceList valid_only (const SourceList &list);
SourceList active_only (const SourceList &list); SourceList active_only (const SourceList &list);
SourceList depth_sorted (const SourceList &list); SourceList depth_sorted (const SourceList &list);
SourceList mixing_sorted (const SourceList &list, glm::vec2 center = glm::vec2(0.f, 0.f)); SourceList mixing_sorted (const SourceList &list, glm::vec2 center = glm::vec2(0.f, 0.f));

View File

@@ -508,6 +508,10 @@ Source *TextureView::getEditOrCurrentSource()
} }
} }
if (_source != nullptr && _source->failed() ) {
_source = nullptr;
}
return _source; return _source;
} }